added sources for Slick

Former-commit-id: 1647fa32ef6894bd7db44f741f07c2f4dcdf9054
Former-commit-id: 0e5810dcfbe1fd59b13e7cabe9f1e93c5542da2d
This commit is contained in:
Song Minjae
2016-12-30 23:29:12 +09:00
parent d24b31e15d
commit 059abff814
329 changed files with 58400 additions and 7 deletions

View File

@@ -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;
}
}
}