toxgene.util.FileLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ToxGene Show documentation
Show all versions of ToxGene Show documentation
Modified ToXGene for the iBench project.
The newest version!
/**
*
*/
package toxgene.util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.JarFile;
import org.apache.log4j.Logger;
/**
* @author lord_pretzel
*
*/
public class FileLoader {
static Logger log = Logger.getLogger(FileLoader.class);
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;
log.debug("load " + method);
// 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;
}
}