Skip to content

Commit 2d4fcaf

Browse files
tonihelestephengold
authored andcommitted
Wrap the input stream in BufferedInputStream (#1613)
* Wrap the input stream in BufferedInputStream * Use BufferedInputStream on the AssetLoader load path * Update the copyright year
1 parent 218a3dc commit 2d4fcaf

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009-2020 jMonkeyEngine
2+
* Copyright (c) 2009-2021 jMonkeyEngine
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -41,6 +41,7 @@
4141
import java.awt.Transparency;
4242
import java.awt.color.ColorSpace;
4343
import java.awt.image.*;
44+
import java.io.BufferedInputStream;
4445
import java.io.IOException;
4546
import java.io.InputStream;
4647
import java.nio.ByteBuffer;
@@ -187,18 +188,13 @@ public Image load(InputStream in, boolean flipY) throws IOException{
187188
public Object load(AssetInfo info) throws IOException {
188189
if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){
189190
boolean flip = ((TextureKey) info.getKey()).isFlipY();
190-
InputStream in = null;
191-
try {
192-
in = info.openStream();
193-
Image img = load(in, flip);
191+
try (InputStream in = info.openStream();
192+
BufferedInputStream bin = new BufferedInputStream(in)) {
193+
Image img = load(bin, flip);
194194
if (img == null){
195195
throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
196196
}
197197
return img;
198-
} finally {
199-
if (in != null){
200-
in.close();
201-
}
202198
}
203199
}else{
204200
throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported");

0 commit comments

Comments
 (0)