com.github.mathiewz.slick.util.FileSystemLocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of modernized-slick Show documentation
Show all versions of modernized-slick Show documentation
The main purpose of this libraryis to modernize and maintain the slick2D library.
The newest version!
package com.github.mathiewz.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 final 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)
*/
@Override
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)
*/
@Override
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;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy