mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-11 06:11:50 +09:00
added sources for Slick
Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054 Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package org.newdawn.slick.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* A resource loading location that searches somewhere on the classpath
|
||||
*
|
||||
* @author kevin
|
||||
*/
|
||||
public class FileSystemLocation implements ResourceLocation {
|
||||
/** The root of the file system to search */
|
||||
private File root;
|
||||
|
||||
/**
|
||||
* Create a new resoruce location based on the file system
|
||||
*
|
||||
* @param root The root of the file system to search
|
||||
*/
|
||||
public FileSystemLocation(File root) {
|
||||
this.root = root;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResourceLocation#getResource(String)
|
||||
*/
|
||||
public URL getResource(String ref) {
|
||||
try {
|
||||
File file = new File(root, ref);
|
||||
if (!file.exists()) {
|
||||
file = new File(ref);
|
||||
}
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return file.toURI().toURL();
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ResourceLocation#getResourceAsStream(String)
|
||||
*/
|
||||
public InputStream getResourceAsStream(String ref) {
|
||||
try {
|
||||
File file = new File(root, ref);
|
||||
if (!file.exists()) {
|
||||
file = new File(ref);
|
||||
}
|
||||
return new FileInputStream(file);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user