fixed image loading when app is packed as jar
https://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream
This commit is contained in:
parent
21643e5d63
commit
c64339c945
|
@ -21,13 +21,9 @@ public class PlantImageDeserializer extends JsonDeserializer<Image> {
|
|||
@Override
|
||||
public Image deserialize(JsonParser parser, DeserializationContext context) throws IOException {
|
||||
Image result = null;
|
||||
URL imageUrl = PlantList.class.getResource(String.format("images/%s", parser.getText()));
|
||||
if (imageUrl != null) {
|
||||
try (InputStream is = new FileInputStream(new File(imageUrl.toURI()))) {
|
||||
InputStream is = PlantList.class.getResourceAsStream(String.format("images/%s", parser.getText()));
|
||||
if (is != null) {
|
||||
result = new Image(is);
|
||||
} catch (IllegalArgumentException | URISyntaxException e) {
|
||||
throw new IOException(String.format("Cannot find Image \"%s\"\n", imageUrl.getFile()));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue