From dc363207e93a5cd0c056d95ccf82d5edb01a2d4a Mon Sep 17 00:00:00 2001 From: ShirosakiMio <852468399@qq.com> Date: Sun, 12 Mar 2023 15:39:18 +0800 Subject: [PATCH] auto close iostream --- .../com/tungsten/fcl/game/TexturesLoader.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/FCL/src/main/java/com/tungsten/fcl/game/TexturesLoader.java b/FCL/src/main/java/com/tungsten/fcl/game/TexturesLoader.java index eea038a7..dedfe1b9 100644 --- a/FCL/src/main/java/com/tungsten/fcl/game/TexturesLoader.java +++ b/FCL/src/main/java/com/tungsten/fcl/game/TexturesLoader.java @@ -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 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; }