test/java/util/zip/GZIP/GZIPInputStreamRead.java
Print this page
rev 3516 : 7021582: convert jar/zip code and tests to use try-with-resources
Reviewed-by: XXX
@@ -42,13 +42,13 @@
for (int j = 0; j < members; j++) {
byte[] src = new byte[rnd.nextInt(8192) + 1];
rnd.nextBytes(src);
srcBAOS.write(src);
- GZIPOutputStream gzos = new GZIPOutputStream(dstBAOS);
+ try (GZIPOutputStream gzos = new GZIPOutputStream(dstBAOS)) {
gzos.write(src);
- gzos.close();
+ }
}
byte[] srcBytes = srcBAOS.toByteArray();
byte[] dstBytes = dstBAOS.toByteArray();
// try different size of buffer to read the
// GZIPInputStream
@@ -73,13 +73,14 @@
private static void test(byte[] src, byte[] dst,
int readBufSize, int gzisBufSize)
throws Throwable
{
- GZIPInputStream gzis = new GZIPInputStream(
+ try (GZIPInputStream gzis = new GZIPInputStream(
new ByteArrayInputStream(dst),
- gzisBufSize);
+ gzisBufSize))
+ {
byte[] result = new byte[src.length + 10];
byte[] buf = new byte[readBufSize];
int n = 0;
int off = 0;
@@ -93,8 +94,8 @@
throw new RuntimeException(
"GZIPInputStream reading failed! " +
", src.len=" + src.length +
", read=" + off);
}
- gzis.close();
+ }
}
}