1313public class ZipCompress {
1414 public static void
1515 main (String [] args ) throws IOException {
16- try (FileOutputStream f =
17- new FileOutputStream ("test.zip" );
18- CheckedOutputStream csum =
19- new CheckedOutputStream (f , new Adler32 ());
20- ZipOutputStream zos = new ZipOutputStream (csum );
21- BufferedOutputStream out =
22- new BufferedOutputStream (zos )) {
16+ try (
17+ FileOutputStream f =
18+ new FileOutputStream ("test.zip" );
19+ CheckedOutputStream csum =
20+ new CheckedOutputStream (f , new Adler32 ());
21+ ZipOutputStream zos = new ZipOutputStream (csum );
22+ BufferedOutputStream out =
23+ new BufferedOutputStream (zos )
24+ ) {
2325 zos .setComment ("A test of Java Zipping" );
2426 // No corresponding getComment(), though.
2527 for (String arg : args ) {
2628 System .out .println ("Writing file " + arg );
27- try (InputStream in = new BufferedInputStream (
28- new FileInputStream (arg ))) {
29+ try (
30+ InputStream in = new BufferedInputStream (
31+ new FileInputStream (arg ))
32+ ) {
2933 zos .putNextEntry (new ZipEntry (arg ));
3034 int c ;
3135 while ((c = in .read ()) != -1 )
@@ -39,13 +43,15 @@ public class ZipCompress {
3943 }
4044 // Now extract the files:
4145 System .out .println ("Reading file" );
42- try (FileInputStream fi =
43- new FileInputStream ("test.zip" );
44- CheckedInputStream csumi =
45- new CheckedInputStream (fi , new Adler32 ());
46- ZipInputStream in2 = new ZipInputStream (csumi );
47- BufferedInputStream bis =
48- new BufferedInputStream (in2 )) {
46+ try (
47+ FileInputStream fi =
48+ new FileInputStream ("test.zip" );
49+ CheckedInputStream csumi =
50+ new CheckedInputStream (fi , new Adler32 ());
51+ ZipInputStream in2 = new ZipInputStream (csumi );
52+ BufferedInputStream bis =
53+ new BufferedInputStream (in2 )
54+ ) {
4955 ZipEntry ze ;
5056 while ((ze = in2 .getNextEntry ()) != null ) {
5157 System .out .println ("Reading file " + ze );
@@ -58,7 +64,9 @@ public class ZipCompress {
5864 "Checksum: " +csumi .getChecksum ().getValue ());
5965 }
6066 // Alternative way to open and read Zip files:
61- try (ZipFile zf = new ZipFile ("test.zip" )) {
67+ try (
68+ ZipFile zf = new ZipFile ("test.zip" )
69+ ) {
6270 Enumeration e = zf .entries ();
6371 while (e .hasMoreElements ()) {
6472 ZipEntry ze2 = (ZipEntry )e .nextElement ();
0 commit comments