code style

This commit is contained in:
Connor Tumbleson 2017-06-29 11:30:00 -04:00
parent 28883538a7
commit f8fe98d9a6

View File

@ -17,11 +17,13 @@
package brut.util; package brut.util;
import brut.common.BrutException; import brut.common.BrutException;
import java.io.*; import java.io.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
/** /**
@ -29,10 +31,9 @@ import org.apache.commons.io.IOUtils;
*/ */
abstract public class Jar { abstract public class Jar {
private final static Set<String> mLoaded = new HashSet<String>(); private final static Set<String> mLoaded = new HashSet<String>();
private final static Map<String, File> mExtracted = private final static Map<String, File> mExtracted = new HashMap<String, File>();
new HashMap<String, File>();
public static File getResourceAsFile(String name, Class clazz) throws BrutException {
public static File getResourceAsFile(String name, Class clazz) throws BrutException {
File file = mExtracted.get(name); File file = mExtracted.get(name);
if (file == null) { if (file == null) {
file = extractToTmp(name, clazz); file = extractToTmp(name, clazz);
@ -60,16 +61,19 @@ abstract public class Jar {
System.load(libFile.getAbsolutePath()); System.load(libFile.getAbsolutePath());
} }
public static File extractToTmp(String resourcePath, Class clazz) throws BrutException { public static File extractToTmp(String resourcePath) throws BrutException {
return extractToTmp(resourcePath, "brut_util_Jar_", clazz);
}
public static File extractToTmp(String resourcePath) throws BrutException {
return extractToTmp(resourcePath, Class.class); return extractToTmp(resourcePath, Class.class);
} }
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) public static File extractToTmp(String resourcePath, Class clazz) throws BrutException {
throws BrutException { return extractToTmp(resourcePath, "brut_util_Jar_", clazz);
}
public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
return extractToTmp(resourcePath, tmpPrefix, Class.class);
}
public static File extractToTmp(String resourcePath, String tmpPrefix, Class clazz) throws BrutException {
try { try {
InputStream in = clazz.getResourceAsStream(resourcePath); InputStream in = clazz.getResourceAsStream(resourcePath);
if (in == null) { if (in == null) {
@ -83,12 +87,7 @@ abstract public class Jar {
out.close(); out.close();
return fileOut; return fileOut;
} catch (IOException ex) { } catch (IOException ex) {
throw new BrutException( throw new BrutException("Could not extract resource: " + resourcePath, ex);
"Could not extract resource: " + resourcePath, ex);
} }
} }
public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException {
return extractToTmp(resourcePath, tmpPrefix, Class.class);
}
} }