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: alanb, dholmes, sherman
*** 42,54 ****
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);
gzos.write(src);
! gzos.close();
}
byte[] srcBytes = srcBAOS.toByteArray();
byte[] dstBytes = dstBAOS.toByteArray();
// try different size of buffer to read the
// GZIPInputStream
--- 42,54 ----
for (int j = 0; j < members; j++) {
byte[] src = new byte[rnd.nextInt(8192) + 1];
rnd.nextBytes(src);
srcBAOS.write(src);
! try (GZIPOutputStream gzos = new GZIPOutputStream(dstBAOS)) {
gzos.write(src);
! }
}
byte[] srcBytes = srcBAOS.toByteArray();
byte[] dstBytes = dstBAOS.toByteArray();
// try different size of buffer to read the
// GZIPInputStream
*** 73,85 ****
private static void test(byte[] src, byte[] dst,
int readBufSize, int gzisBufSize)
throws Throwable
{
! GZIPInputStream gzis = new GZIPInputStream(
! new ByteArrayInputStream(dst),
! gzisBufSize);
byte[] result = new byte[src.length + 10];
byte[] buf = new byte[readBufSize];
int n = 0;
int off = 0;
--- 73,85 ----
private static void test(byte[] src, byte[] dst,
int readBufSize, int gzisBufSize)
throws Throwable
{
! try (ByteArrayInputStream bais = new ByteArrayInputStream(dst);
! GZIPInputStream gzis = new GZIPInputStream(bais, gzisBufSize))
! {
byte[] result = new byte[src.length + 10];
byte[] buf = new byte[readBufSize];
int n = 0;
int off = 0;
*** 93,100 ****
throw new RuntimeException(
"GZIPInputStream reading failed! " +
", src.len=" + src.length +
", read=" + off);
}
! gzis.close();
}
}
--- 93,100 ----
throw new RuntimeException(
"GZIPInputStream reading failed! " +
", src.len=" + src.length +
", read=" + off);
}
! }
}
}