/**
* Load a resource based on a path under the img folder
*
* @param path The path + name of the file to load
* @return The stream loaded from the file system
* @throws java.io.FileNotFoundException Indicates a failure to read the resource
*/
protected ImageInputStream getImgRes(String path) throws IOException {
String fullPath = imgPath + path;
// Try to load resource from jar
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullPath);
if (is == null) {
return new FileImageInputStream(new File(fullPath)); // No Jar let's Try the local FileSystem
} else {
return null;
}
}
I've written this function so It would return an ImageInputStream when loading images from a jar.
But I get an sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream when loading from a Jar.
So I wanted to do a instanceof test and downcast it:
if(is instanceof JarURLConnection) {
// try to get an ImageInputStream out of it
}
but I'm stuck at the instanceof, they are 'inconvertable types' I don't understand the method returns InputStream
but JarURLConnection doesn't extends it.
public InputStream getResourceAsStream(String name) {
How can I test if I have a JarURLConnection and how would I retrieve an ImageInputStream out of it?