39 lines
881 B
Java
39 lines
881 B
Java
package chess.view;
|
|
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
public class AssetManager {
|
|
|
|
private static final String gradleBase = "app/src/main/resources/";
|
|
|
|
public static InputStream getResource(String name) {
|
|
// we first search it in files
|
|
InputStream inputStream = getFileInputStream(name);
|
|
if (inputStream != null)
|
|
return inputStream;
|
|
|
|
inputStream = getFileInputStream(gradleBase + name);
|
|
if (inputStream != null)
|
|
return inputStream;
|
|
// then in the jar
|
|
return ClassLoader.getSystemResourceAsStream(name);
|
|
}
|
|
|
|
private static InputStream getFileInputStream(String path) {
|
|
File f = new File(path);
|
|
if (f.exists()) {
|
|
FileInputStream fis;
|
|
try {
|
|
fis = new FileInputStream(f);
|
|
return fis;
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|