auto close iostream

This commit is contained in:
ShirosakiMio 2023-03-12 15:39:18 +08:00
parent 6f01e6b7a5
commit dc363207e9
1 changed files with 12 additions and 5 deletions

View File

@ -112,10 +112,13 @@ public final class TexturesLoader {
}
}
}
Bitmap img = BitmapFactory.decodeStream(Files.newInputStream(file));
if (img == null)
Bitmap img;
try(InputStream in = Files.newInputStream(file)){
img = BitmapFactory.decodeStream(in);
}
if (img == null) {
throw new IOException("Texture is malformed");
}
Map<String, String> metadata = texture.getMetadata();
if (metadata == null) {
@ -144,9 +147,13 @@ public final class TexturesLoader {
}
}
Bitmap img = BitmapFactory.decodeStream(Files.newInputStream(file));
if (img == null)
Bitmap img;
try(InputStream in = Files.newInputStream(file)){
img = BitmapFactory.decodeStream(in);
}
if (img == null) {
throw new IOException("Texture is malformed");
}
return img;
}