You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2018/07/28 14:26:23 UTC
[2/2] commons-compress git commit: COMPRESS-460 rudimentary javadocs
and tests
COMPRESS-460 rudimentary javadocs and tests
closes #68
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/792da673
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/792da673
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/792da673
Branch: refs/heads/master
Commit: 792da6735e532a6e7f2f2a017d999a8f7c30f2fe
Parents: c5c231e
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sat Jul 28 16:24:59 2018 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sat Jul 28 16:25:18 2018 +0200
----------------------------------------------------------------------
src/changes/changes.xml | 5 +++
.../zstandard/ZstdCompressorOutputStream.java | 33 +++++++++++++-
.../zstandard/ZstdRoundtripTest.java | 45 +++++++++++++++++++-
3 files changed, 80 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/792da673/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index de587a0..bb477f3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,11 @@ The <action> type attribute can be add,update,fix,remove.
The cpio stream didn't handle archives using a multi-byte
encoding properly.
</action>
+ <action issue="COMPRESS-460" type="add" date="2018-07-28"
+ due-to="Carmi Grushko">
+ It is now possible to specify the arguments of zstd-jni's
+ ZstdOutputStream constructors via Commons Compress as well.
+ </action>
</release>
<release version="1.17" date="2018-06-03"
description="Release 1.17">
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/792da673/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorOutputStream.java
index 3a393e9..4027914 100644
--- a/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/compressors/zstandard/ZstdCompressorOutputStream.java
@@ -34,18 +34,47 @@ public class ZstdCompressorOutputStream extends CompressorOutputStream {
private final ZstdOutputStream encOS;
- public ZstdCompressorOutputStream(final OutputStream outStream, int level, boolean closeFrameOnFlush, boolean useChecksum) throws IOException {
+ /**
+ * Wraps the given stream into a zstd-jni ZstdOutputStream.
+ * @param level value for zstd-jni's level argument
+ * @param closeFrameOnFlush value for zstd-jni's closeFrameOnFlush argument
+ * @param useChecksum value for zstd-jni's useChecksum argument
+ * @throws IOException if zstd-jni does
+ * @since 1.18
+ */
+ public ZstdCompressorOutputStream(final OutputStream outStream, int level, boolean closeFrameOnFlush,
+ boolean useChecksum) throws IOException {
this.encOS = new ZstdOutputStream(outStream, level, closeFrameOnFlush, useChecksum);
}
- public ZstdCompressorOutputStream(final OutputStream outStream, int level, boolean closeFrameOnFlush) throws IOException {
+ /**
+ * Wraps the given stream into a zstd-jni ZstdOutputStream using the default value for {@code useChecksum}.
+ * @param level value for zstd-jni's level argument
+ * @param closeFrameOnFlush value for zstd-jni's closeFrameOnFlush argument
+ * @throws IOException if zstd-jni does
+ * @since 1.18
+ */
+ public ZstdCompressorOutputStream(final OutputStream outStream, int level, boolean closeFrameOnFlush)
+ throws IOException {
this.encOS = new ZstdOutputStream(outStream, level, closeFrameOnFlush);
}
+ /**
+ * Wraps the given stream into a zstd-jni ZstdOutputStream using the default values for {@code closeFrameOnFlush}
+ * and {@code useChecksum}.
+ * @param level value for zstd-jni's level argument
+ * @throws IOException if zstd-jni does
+ * @since 1.18
+ */
public ZstdCompressorOutputStream(final OutputStream outStream, int level) throws IOException {
this.encOS = new ZstdOutputStream(outStream, level);
}
+ /**
+ * Wraps the given stream into a zstd-jni ZstdOutputStream using the default values for {@code level}, {@code
+ * closeFrameOnFlush} and {@code useChecksum}.
+ * @throws IOException if zstd-jni does
+ */
public ZstdCompressorOutputStream(final OutputStream outStream) throws IOException {
this.encOS = new ZstdOutputStream(outStream);
}
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/792da673/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
index 3c1469b..6e9dfef 100644
--- a/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/zstandard/ZstdRoundtripTest.java
@@ -31,14 +31,27 @@ import org.junit.Test;
public class ZstdRoundtripTest extends AbstractTestCase {
+ private interface OutputStreamCreator {
+ ZstdCompressorOutputStream wrap(FileOutputStream os) throws IOException;
+ }
+
@Test
public void directRoundtrip() throws Exception {
+ roundtrip(new OutputStreamCreator() {
+ @Override
+ public ZstdCompressorOutputStream wrap(FileOutputStream os) throws IOException {
+ return new ZstdCompressorOutputStream(os);
+ }
+ });
+ }
+
+ private void roundtrip(OutputStreamCreator oc) throws IOException {
File input = getFile("bla.tar");
long start = System.currentTimeMillis();
final File output = new File(dir, input.getName() + ".zstd");
try (FileInputStream is = new FileInputStream(input);
FileOutputStream os = new FileOutputStream(output);
- ZstdCompressorOutputStream zos = new ZstdCompressorOutputStream(os)) {
+ ZstdCompressorOutputStream zos = oc.wrap(os)) {
IOUtils.copy(is, zos);
}
System.err.println(input.getName() + " written, uncompressed bytes: " + input.length()
@@ -73,4 +86,34 @@ public class ZstdRoundtripTest extends AbstractTestCase {
}
}
+ @Test
+ public void roundtripWithCustomLevel() throws Exception {
+ roundtrip(new OutputStreamCreator() {
+ @Override
+ public ZstdCompressorOutputStream wrap(FileOutputStream os) throws IOException {
+ return new ZstdCompressorOutputStream(os, 1);
+ }
+ });
+ }
+
+ @Test
+ public void roundtripWithCloseFrameOnFlush() throws Exception {
+ roundtrip(new OutputStreamCreator() {
+ @Override
+ public ZstdCompressorOutputStream wrap(FileOutputStream os) throws IOException {
+ return new ZstdCompressorOutputStream(os, 3, true);
+ }
+ });
+ }
+
+ @Test
+ public void roundtripWithChecksum() throws Exception {
+ roundtrip(new OutputStreamCreator() {
+ @Override
+ public ZstdCompressorOutputStream wrap(FileOutputStream os) throws IOException {
+ return new ZstdCompressorOutputStream(os, 3, false, true);
+ }
+ });
+ }
+
}