
toxgene.util.FileLoader Maven / Gradle / Ivy
/**
*
*/
package toxgene.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;
/**
* @author lord_pretzel
*
*/
public class FileLoader {
public static FileLoader inst = new FileLoader();
public enum LoadMethod {
LOAD_SYSTEM_CLASSLOADER,
LOAD_JARFILE
}
private LoadMethod method = LoadMethod.LOAD_SYSTEM_CLASSLOADER;
private JarFile j = null;
public FileLoader () {
}
public void setupJarFileForLoading (String path) throws IOException {
if (path == null)
{
String tgHome = System.getProperty("ToXgene_home");
File p;
if (tgHome == null){
tgHome = ".";
}
p = new File(tgHome, "toxgene.jar");
if (p.exists()) {
j = new JarFile(p);
}
method = LoadMethod.LOAD_JARFILE;
}
else {
j = new JarFile(path);
method = LoadMethod.LOAD_JARFILE;
}
}
public InputStream loadFile(String path) throws IOException {
InputStream result = null;
// try system classloader first
if (method == LoadMethod.LOAD_SYSTEM_CLASSLOADER)
result = ClassLoader.getSystemResourceAsStream(path);
if (result != null)
return result;
result = j.getInputStream(j.getEntry(path));
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy