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,90 ****
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);
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);
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();
--- 62,86 ----
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 (GZIPOutputStream s = new GZIPOutputStream(out)) {
for (long i = 0; i < count; i++)
s.write(data, 0, data.length);
} catch (Throwable t) { trouble = t; }}};
Thread uncompressor = new Thread() { public void run() {
! 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");
} catch (Throwable t) { trouble = t; }}};
compressor.start(); uncompressor.start();
compressor.join(); uncompressor.join();