diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java index c44f5cb4078..31bf4ee3497 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ZipTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/ZipTest.java @@ -219,15 +219,10 @@ private ZipFile newZipFile(final File file) throws IOException { } private void readStream(final InputStream in, final ArchiveEntry entry, final Map>> map) throws IOException { - final byte[] buf = new byte[4096]; final InputStreamStatistics stats = (InputStreamStatistics) in; - while (in.read(buf) != -1) { - // consume all. - } - + IOUtils.consume(in); final String name = entry.getName(); final List> list = map.computeIfAbsent(name, k -> new ArrayList<>()); - final long t = stats.getUncompressedCount(); final long b = stats.getCompressedCount(); list.add(Arrays.asList(t, b)); diff --git a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java index 3b854993eb8..dd974cbb49d 100644 --- a/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/brotli/BrotliCompressorInputStreamTest.java @@ -54,10 +54,7 @@ public void testBrotliDecode() throws IOException { BrotliCompressorInputStream brotliInputStream = new BrotliCompressorInputStream(inputStream)) { final byte[] expected = readAllBytes("brotli.testdata.uncompressed"); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int readByte = -1; - while ((readByte = brotliInputStream.read()) != -1) { - bos.write(readByte); - } + IOUtils.copy(brotliInputStream, bos); assertArrayEquals(expected, bos.toByteArray()); } } diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java index f07fda3837f..c8801097043 100644 --- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorInputStreamTest.java @@ -142,10 +142,7 @@ public void testZstdDecode() throws IOException { ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream)) { final byte[] expected = readAllBytes("zstandard.testdata"); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int readByte = -1; - while ((readByte = zstdInputStream.read()) != -1) { - bos.write(readByte); - } + IOUtils.copy(zstdInputStream, bos); assertArrayEquals(expected, bos.toByteArray()); } } @@ -157,10 +154,7 @@ public void testZstdDecodeWithNoPool() throws IOException { ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, NoPool.INSTANCE)) { final byte[] expected = readAllBytes("zstandard.testdata"); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int readByte = -1; - while ((readByte = zstdInputStream.read()) != -1) { - bos.write(readByte); - } + IOUtils.copy(zstdInputStream, bos); assertArrayEquals(expected, bos.toByteArray()); } } @@ -172,10 +166,7 @@ public void testZstdDecodeWithRecyclingBufferPool() throws IOException { ZstdCompressorInputStream zstdInputStream = new ZstdCompressorInputStream(inputStream, RecyclingBufferPool.INSTANCE)) { final byte[] expected = readAllBytes("zstandard.testdata"); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); - int readByte = -1; - while ((readByte = zstdInputStream.read()) != -1) { - bos.write(readByte); - } + IOUtils.copy(zstdInputStream, bos); assertArrayEquals(expected, bos.toByteArray()); } }