@@ -152,10 +152,12 @@ public static byte[] readFile(final File file) throws IOException {
152
152
if (length > Integer .MAX_VALUE ) {
153
153
throw new IllegalArgumentException ("File too large" );
154
154
}
155
- final DataInputStream dis = new DataInputStream (new FileInputStream (file ));
156
155
final byte [] bytes = new byte [(int ) length ];
157
- dis .readFully (bytes );
158
- dis .close ();
156
+ try (final DataInputStream dis = new DataInputStream (new FileInputStream (
157
+ file )))
158
+ {
159
+ dis .readFully (bytes );
160
+ }
159
161
return bytes ;
160
162
}
161
163
@@ -168,13 +170,9 @@ public static byte[] readFile(final File file) throws IOException {
168
170
public static void writeFile (final File file , final byte [] bytes )
169
171
throws IOException
170
172
{
171
- final FileOutputStream out = new FileOutputStream (file );
172
- try {
173
+ try (final FileOutputStream out = new FileOutputStream (file )) {
173
174
out .write (bytes );
174
175
}
175
- finally {
176
- out .close ();
177
- }
178
176
}
179
177
180
178
public static String stripFilenameVersion (final String filename ) {
@@ -577,29 +575,29 @@ else if (protocol.equals("jar")) {
577
575
578
576
final JarURLConnection connection =
579
577
(JarURLConnection ) new URL (baseURL ).openConnection ();
580
- final JarFile jar = connection .getJarFile ();
581
- for (final JarEntry entry : new IteratorPlus <>(jar .entries ())) {
582
- final String urlEncoded =
583
- new URI (null , null , entry .getName (), null ).toString ();
584
- if (urlEncoded .length () > prefix .length () && // omit directory itself
585
- urlEncoded .startsWith (prefix ))
586
- {
587
- if (filesOnly && urlEncoded .endsWith ("/" )) {
588
- // URL is directory; exclude it
589
- continue ;
590
- }
591
- if (!recurse ) {
592
- // check whether this URL is a *direct* child of the directory
593
- final int slash = urlEncoded .indexOf ("/" , prefix .length ());
594
- if (slash >= 0 && slash != urlEncoded .length () - 1 ) {
595
- // not a direct child
578
+ try (final JarFile jar = connection .getJarFile ()) {
579
+ for (final JarEntry entry : new IteratorPlus <>(jar .entries ())) {
580
+ final String urlEncoded =
581
+ new URI (null , null , entry .getName (), null ).toString ();
582
+ if (urlEncoded .length () > prefix .length () && // omit directory itself
583
+ urlEncoded .startsWith (prefix ))
584
+ {
585
+ if (filesOnly && urlEncoded .endsWith ("/" )) {
586
+ // URL is directory; exclude it
596
587
continue ;
597
588
}
589
+ if (!recurse ) {
590
+ // check whether this URL is a *direct* child of the directory
591
+ final int slash = urlEncoded .indexOf ("/" , prefix .length ());
592
+ if (slash >= 0 && slash != urlEncoded .length () - 1 ) {
593
+ // not a direct child
594
+ continue ;
595
+ }
596
+ }
597
+ result .add (new URL (baseURL + urlEncoded ));
598
598
}
599
- result .add (new URL (baseURL + urlEncoded ));
600
599
}
601
600
}
602
- jar .close ();
603
601
}
604
602
catch (final IOException e ) {
605
603
e .printStackTrace ();
0 commit comments