You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/08/29 22:44:35 UTC
[commons-compress] branch master updated (5ff8af5f -> c6c99897)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from 5ff8af5f Use try-with-resources
new 95e67f06 Use try-with-resources
new 0faa52d9 Use better test API
new c6c99897 Use better test API
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../deflate/DeflateCompressorInputStreamTest.java | 36 ++++++----------------
.../compress/compressors/lz4/FactoryTest.java | 14 ++++-----
2 files changed, 17 insertions(+), 33 deletions(-)
[commons-compress] 01/03: Use try-with-resources
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 95e67f0611897811168ce8f0e342204b3cb3cd0c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 29 17:29:33 2023 -0400
Use try-with-resources
---
.../deflate/DeflateCompressorInputStreamTest.java | 30 ++++++++--------------
1 file changed, 10 insertions(+), 20 deletions(-)
diff --git a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
index 7a02bc7a..58a466bb 100644
--- a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
@@ -35,11 +35,9 @@ public class DeflateCompressorInputStreamTest {
@Test
public void availableShouldReturnNonZero() throws IOException {
final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath())) {
- final DeflateCompressorInputStream in =
- new DeflateCompressorInputStream(is);
+ try (InputStream is = Files.newInputStream(input.toPath());
+ DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
assertTrue(in.available() > 0);
- in.close();
}
}
@@ -47,49 +45,41 @@ public class DeflateCompressorInputStreamTest {
public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
final File input = AbstractTestCase.getFile("bla.tar.deflatez");
final byte[] buf = new byte[2];
- try (InputStream is = Files.newInputStream(input.toPath())) {
- final DeflateCompressorInputStream in =
- new DeflateCompressorInputStream(is);
+ try (InputStream is = Files.newInputStream(input.toPath());
+ DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read(buf));
assertEquals(-1, in.read(buf));
- in.close();
}
}
@Test
public void shouldBeAbleToSkipAByte() throws IOException {
final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath())) {
- final DeflateCompressorInputStream in =
- new DeflateCompressorInputStream(is);
+ try (InputStream is = Files.newInputStream(input.toPath());
+ DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
assertEquals(1, in.skip(1));
- in.close();
}
}
@Test
public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath())) {
- final DeflateCompressorInputStream in =
- new DeflateCompressorInputStream(is);
+ try (InputStream is = Files.newInputStream(input.toPath());
+ DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read());
assertEquals(-1, in.read());
- in.close();
}
}
@Test
public void singleByteReadWorksAsExpected() throws IOException {
final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath())) {
- final DeflateCompressorInputStream in =
- new DeflateCompressorInputStream(is);
+ try (InputStream is = Files.newInputStream(input.toPath());
+ DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
// tar header starts with filename "test1.xml"
assertEquals('t', in.read());
- in.close();
}
}
[commons-compress] 02/03: Use better test API
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 0faa52d95f1024696da7f59f5f6a02b9fbd11dbc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 29 17:30:54 2023 -0400
Use better test API
---
.../deflate/DeflateCompressorInputStreamTest.java | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
index 58a466bb..0192beff 100644
--- a/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/deflate/DeflateCompressorInputStreamTest.java
@@ -21,7 +21,6 @@ package org.apache.commons.compress.compressors.deflate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
@@ -34,8 +33,7 @@ public class DeflateCompressorInputStreamTest {
@Test
public void availableShouldReturnNonZero() throws IOException {
- final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(AbstractTestCase.getPath("bla.tar.deflatez"));
DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
assertTrue(in.available() > 0);
}
@@ -43,9 +41,8 @@ public class DeflateCompressorInputStreamTest {
@Test
public void multiByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
- final File input = AbstractTestCase.getFile("bla.tar.deflatez");
final byte[] buf = new byte[2];
- try (InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(AbstractTestCase.getPath("bla.tar.deflatez"));
DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read(buf));
@@ -55,8 +52,7 @@ public class DeflateCompressorInputStreamTest {
@Test
public void shouldBeAbleToSkipAByte() throws IOException {
- final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(AbstractTestCase.getPath("bla.tar.deflatez"));
DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
assertEquals(1, in.skip(1));
}
@@ -64,8 +60,7 @@ public class DeflateCompressorInputStreamTest {
@Test
public void singleByteReadConsistentlyReturnsMinusOneAtEof() throws IOException {
- final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(AbstractTestCase.getPath("bla.tar.deflatez"));
DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
IOUtils.toByteArray(in);
assertEquals(-1, in.read());
@@ -75,8 +70,7 @@ public class DeflateCompressorInputStreamTest {
@Test
public void singleByteReadWorksAsExpected() throws IOException {
- final File input = AbstractTestCase.getFile("bla.tar.deflatez");
- try (InputStream is = Files.newInputStream(input.toPath());
+ try (InputStream is = Files.newInputStream(AbstractTestCase.getPath("bla.tar.deflatez"));
DeflateCompressorInputStream in = new DeflateCompressorInputStream(is)) {
// tar header starts with filename "test1.xml"
assertEquals('t', in.read());
[commons-compress] 03/03: Use better test API
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit c6c99897905756e2fea3712c532f94d8ce2f75f0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Aug 29 17:34:06 2023 -0400
Use better test API
---
.../commons/compress/compressors/lz4/FactoryTest.java | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java b/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
index 038b89db..b8f39221 100644
--- a/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/lz4/FactoryTest.java
@@ -20,10 +20,10 @@ package org.apache.commons.compress.compressors.lz4;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
+import java.nio.file.Path;
import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.compressors.CompressorStreamFactory;
@@ -43,18 +43,18 @@ public class FactoryTest extends AbstractTestCase {
}
private void roundtripViaFactory(final String format) throws Exception {
- final File input = getFile("bla.tar");
+ final Path input = getPath("bla.tar");
long start = System.currentTimeMillis();
- final File outputSz = new File(dir, input.getName() + "." + format + ".lz4");
- try (OutputStream os = Files.newOutputStream(outputSz.toPath());
+ final Path outputSz = dir.toPath().resolve(input.getFileName() + "." + format + ".lz4");
+ try (OutputStream os = Files.newOutputStream(outputSz);
OutputStream los = new CompressorStreamFactory().createCompressorOutputStream(format, os)) {
- Files.copy(input.toPath(), los);
+ Files.copy(input, los);
}
// System.err.println(input.getName() + " written, uncompressed bytes: " + input.length()
// + ", compressed bytes: " + outputSz.length() + " after " + (System.currentTimeMillis() - start) + "ms");
start = System.currentTimeMillis();
- try (InputStream is = Files.newInputStream(input.toPath());
- InputStream sis = new CompressorStreamFactory().createCompressorInputStream(format, Files.newInputStream(outputSz.toPath()))) {
+ try (InputStream is = Files.newInputStream(input);
+ InputStream sis = new CompressorStreamFactory().createCompressorInputStream(format, Files.newInputStream(outputSz))) {
final byte[] expected = IOUtils.toByteArray(is);
final byte[] actual = IOUtils.toByteArray(sis);
assertArrayEquals(expected, actual);