From ab525c0a154f53750ac057f63bb1724cb2c98fad Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 18 Nov 2017 09:45:25 +1100 Subject: BUILDTOOLS-19: Close ZipFile after extraction --- src/main/java/org/spigotmc/builder/Builder.java | 62 ++++++++++++++----------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'src/main/java/org/spigotmc/builder') diff --git a/src/main/java/org/spigotmc/builder/Builder.java b/src/main/java/org/spigotmc/builder/Builder.java index 3204307..c11c47a 100644 --- a/src/main/java/org/spigotmc/builder/Builder.java +++ b/src/main/java/org/spigotmc/builder/Builder.java @@ -668,42 +668,48 @@ public class Builder targetFolder.mkdir(); ZipFile zip = new ZipFile( zipFile ); - for ( Enumeration entries = zip.entries(); entries.hasMoreElements(); ) + try { - ZipEntry entry = entries.nextElement(); - - if ( filter != null ) + for ( Enumeration entries = zip.entries(); entries.hasMoreElements(); ) { - if ( !filter.apply( entry.getName() ) ) + ZipEntry entry = entries.nextElement(); + + if ( filter != null ) { - continue; + if ( !filter.apply( entry.getName() ) ) + { + continue; + } } - } - File outFile = new File( targetFolder, entry.getName() ); + File outFile = new File( targetFolder, entry.getName() ); - if ( entry.isDirectory() ) - { - outFile.mkdirs(); - continue; - } - if ( outFile.getParentFile() != null ) - { - outFile.getParentFile().mkdirs(); - } + if ( entry.isDirectory() ) + { + outFile.mkdirs(); + continue; + } + if ( outFile.getParentFile() != null ) + { + outFile.getParentFile().mkdirs(); + } - InputStream is = zip.getInputStream( entry ); - OutputStream os = new FileOutputStream( outFile ); - try - { - ByteStreams.copy( is, os ); - } finally - { - is.close(); - os.close(); - } + InputStream is = zip.getInputStream( entry ); + OutputStream os = new FileOutputStream( outFile ); + try + { + ByteStreams.copy( is, os ); + } finally + { + is.close(); + os.close(); + } - System.out.println( "Extracted: " + outFile ); + System.out.println( "Extracted: " + outFile ); + } + } finally + { + zip.close(); } } -- cgit v1.2.3