From 72324feaf34c7a84ef7b2b694cdfea167497f640 Mon Sep 17 00:00:00 2001 From: Matthew Messinger Date: Fri, 24 Aug 2018 21:38:29 -0400 Subject: [PATCH] Fix file lock issues with the skin cache --- .../voxelmodpack/hdskins/ThreadDownloadImageETag.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hdskins/java/com/voxelmodpack/hdskins/ThreadDownloadImageETag.java b/src/hdskins/java/com/voxelmodpack/hdskins/ThreadDownloadImageETag.java index 65446d36..3f9ba045 100644 --- a/src/hdskins/java/com/voxelmodpack/hdskins/ThreadDownloadImageETag.java +++ b/src/hdskins/java/com/voxelmodpack/hdskins/ThreadDownloadImageETag.java @@ -193,7 +193,8 @@ public class ThreadDownloadImageETag extends SimpleTexture { Files.createDirectories(cacheFile.getParent()); Files.copy(resp.getInputStream(), cacheFile); - BufferedImage bufferedimage = ImageIO.read(Files.newInputStream(cacheFile)); + try (InputStream in = Files.newInputStream(cacheFile)) { + BufferedImage bufferedimage = ImageIO.read(in); // maybe write the etag to disk Header eTag = resp.getResponse().getFirstHeader(HttpHeaders.ETAG); @@ -201,10 +202,11 @@ public class ThreadDownloadImageETag extends SimpleTexture { Files.write(eTagFile, Collections.singleton(eTag.getValue())); } - if (imageBuffer != null) { - bufferedimage = imageBuffer.parseUserSkin(bufferedimage); + if (imageBuffer != null) { + bufferedimage = imageBuffer.parseUserSkin(bufferedimage); + } + setBufferedImage(bufferedimage); } - setBufferedImage(bufferedimage); } } catch (Exception exception) { LOGGER.error("Couldn\'t download http texture", exception);