@@ -121,11 +121,9 @@ private static void create(ILoader<?> loader, boolean clean) throws Exception {
121121 setState ("Bytecode Viewer Boot Screen - Downloading " + fileName + "..." );
122122 System .out .println ("Downloading " + fileName );
123123
124- InputStream is = null ;
125- FileOutputStream fos = null ;
126- try {
127- is = new URL ("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName ).openConnection ().getInputStream ();
128- fos = new FileOutputStream (file );
124+ try (InputStream is = new URL ("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName )
125+ .openConnection ().getInputStream ();
126+ FileOutputStream fos = new FileOutputStream (file )) {
129127 System .out .println ("Downloading from " + s );
130128 byte [] buffer = new byte [8192 ];
131129 int len ;
@@ -143,19 +141,6 @@ private static void create(ILoader<?> loader, boolean clean) throws Exception {
143141 } else
144142 flag = false ;
145143 }
146- } finally {
147- try {
148- if (is != null ) {
149- is .close ();
150- }
151- } finally {
152- if (fos != null ) {
153- fos .flush ();
154- }
155- if (fos != null ) {
156- fos .close ();
157- }
158- }
159144 }
160145
161146 try {
@@ -233,7 +218,7 @@ private static void create(ILoader<?> loader, boolean clean) throws Exception {
233218 try {
234219 ExternalResource res = new EmptyExternalResource <>(f .toURI ().toURL ());
235220 loader .bind (res );
236- System .out .println ("Succesfully loaded " + f .getName ());
221+ System .out .println ("Successfully loaded " + f .getName ());
237222 } catch (Exception e ) {
238223 e .printStackTrace ();
239224 f .delete ();
@@ -314,24 +299,22 @@ public static void dropKrakatau() {
314299
315300 setState ("Bytecode Viewer Boot Screen - Extracting Krakatau" );
316301 System .out .println ("Extracting Krakatau" );
317- try {
318302
319- while (temp .exists ())
320- temp .delete ();
321-
322- InputStream is = BytecodeViewer .class .getClassLoader ().getResourceAsStream ("Krakatau-" + Constants .krakatauVersion + ".zip" );
323- FileOutputStream baos = new FileOutputStream (temp );
303+ while (temp .exists ())
304+ temp .delete ();
324305
306+ try (InputStream is = BytecodeViewer .class .getClassLoader ().getResourceAsStream ("Krakatau-"
307+ + Constants .krakatauVersion + ".zip" );
308+ FileOutputStream baos = new FileOutputStream (temp )) {
325309 int r ;
326310 byte [] buffer = new byte [8192 ];
327311 while ((r = Objects .requireNonNull (is ).read (buffer )) >= 0 ) {
328312 baos .write (buffer , 0 , r );
329313 }
330314
331- baos .close ();
332315 ZipUtils .unzipFilesToPath (temp .getAbsolutePath (), krakatauDirectory .getAbsolutePath ());
333316 temp .delete ();
334- System .out .println ("Succesfully extracted Krakatau" );
317+ System .out .println ("Successfully extracted Krakatau" );
335318 } catch (Exception e ) {
336319 setState ("Bytecode Viewer Boot Screen - ERROR, please contact @Konloch with your stacktrace." );
337320 BytecodeViewer .handleException (e );
@@ -349,25 +332,22 @@ public static void dropEnjarify() {
349332
350333 setState ("Bytecode Viewer Boot Screen - Extracting Enjarify" );
351334 System .out .println ("Extracting Enjarify" );
352-
353- try {
354- while (temp .exists ())
355- temp .delete ();
356335
357- InputStream is =
358- BytecodeViewer .class .getClassLoader ().getResourceAsStream ("enjarify-" + Constants .enjarifyVersion + ".zip" );
359- FileOutputStream baos = new FileOutputStream (temp );
336+ while (temp .exists ())
337+ temp .delete ();
360338
339+ try (InputStream is = BytecodeViewer .class .getClassLoader ().getResourceAsStream ("enjarify-" +
340+ Constants .enjarifyVersion + ".zip" );
341+ FileOutputStream baos = new FileOutputStream (temp )) {
361342 int r ;
362343 byte [] buffer = new byte [8192 ];
363344 while ((r = Objects .requireNonNull (is ).read (buffer )) >= 0 ) {
364345 baos .write (buffer , 0 , r );
365346 }
366347
367- baos .close ();
368348 ZipUtils .unzipFilesToPath (temp .getAbsolutePath (), enjarifyDirectory .getAbsolutePath ());
369349 temp .delete ();
370- System .out .println ("Succesfully extracted Enjarify" );
350+ System .out .println ("Successfully extracted Enjarify" );
371351 } catch (Exception e ) {
372352 setState ("Bytecode Viewer Boot Screen - ERROR, please contact @Konloch with your stacktrace." );
373353 BytecodeViewer .handleException (e );
@@ -388,11 +368,9 @@ public static void downloadZipsOnly() throws Exception {
388368 setState ("Bytecode Viewer Boot Screen - Downloading " + fileName + "..." );
389369 System .out .println ("Downloading " + fileName );
390370
391- InputStream is = null ;
392- FileOutputStream fos = null ;
393- try {
394- is = new URL ("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName ).openConnection ().getInputStream ();
395- fos = new FileOutputStream (file );
371+ try (InputStream is = new URL ("https://github.com/Konloch/bytecode-viewer/raw/master/libs/" + fileName )
372+ .openConnection ().getInputStream ();
373+ FileOutputStream fos = new FileOutputStream (file )) {
396374 System .out .println ("Downloading from " + s );
397375 byte [] buffer = new byte [8192 ];
398376 int len ;
@@ -412,19 +390,6 @@ public static void downloadZipsOnly() throws Exception {
412390 }
413391 } catch (Exception e ) {
414392 e .printStackTrace ();
415- } finally {
416- try {
417- if (is != null ) {
418- is .close ();
419- }
420- } finally {
421- if (fos != null ) {
422- fos .flush ();
423- }
424- if (fos != null ) {
425- fos .close ();
426- }
427- }
428393 }
429394
430395 try {
0 commit comments