test/java/util/zip/GZIP/Accordion.java

Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX

@@ -62,29 +62,25 @@
         for (int i = 0; i < data.length; i++)
             data[i] = (byte)random.nextInt(255);
         System.out.println("count="+count);
 
         Thread compressor = new Thread() { public void run() {
-            try {
-                final GZIPOutputStream s = new GZIPOutputStream(out);
+            try (GZIPOutputStream s = new GZIPOutputStream(out)) {
                 for (long i = 0; i < count; i++)
                     s.write(data, 0, data.length);
-                s.close();
             } catch (Throwable t) { trouble = t; }}};
 
         Thread uncompressor = new Thread() { public void run() {
-            try {
-                final GZIPInputStream s = new GZIPInputStream(in);
+            try (GZIPInputStream s = new GZIPInputStream(in)) {
                 final byte[] maybeBytes = new byte[data.length];
                 for (long i = 0; i < count; i++) {
                     readFully(s, maybeBytes);
                     if (! Arrays.equals(data, maybeBytes))
                         throw new Exception("data corruption");
                 }
                 if (s.read(maybeBytes, 0, 1) > 0)
                     throw new Exception("Unexpected NON-EOF");
-                s.close();
             } catch (Throwable t) { trouble = t; }}};
 
         compressor.start(); uncompressor.start();
         compressor.join();  uncompressor.join();