commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject [2/2] commons-compress git commit: [COMPRESS-368]
Date Wed, 16 Nov 2016 06:21:58 GMT
[COMPRESS-368]

Allow compressor extensions through a standard JRE ServiceLoader.
Revisit new interface to add decompress until EOF.

Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/350f01c7
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/350f01c7
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/350f01c7

Branch: refs/heads/master
Commit: 350f01c78374b4df99c1a84cc32122eeeb48b036
Parents: 545c399
Author: Gary Gregory <ggregory@apache.org>
Authored: Tue Nov 15 22:21:55 2016 -0800
Committer: Gary Gregory <ggregory@apache.org>
Committed: Tue Nov 15 22:21:55 2016 -0800

----------------------------------------------------------------------
 .../compressors/CompressorStreamFactory.java    | 29 ++++++++++++--------
 .../compressors/CompressorStreamProvider.java   |  7 ++++-
 .../CompressorStreamFactoryRoundtripTest.java   |  2 +-
 .../TestCompressorStreamProvider.java           |  7 +++--
 4 files changed, 28 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/350f01c7/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
index 81725f1..03baa1d 100644
--- a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
@@ -188,9 +188,9 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
         return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String,
CompressorStreamProvider>>() {
             @Override
             public SortedMap<String, CompressorStreamProvider> run() {
-                TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
+                final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
                 putAll(SINGLETON.getInputStreamCompressorNames(), SINGLETON, map);
-                for (CompressorStreamProvider provider : findCompressorStreamProviders())
{
+                for (final CompressorStreamProvider provider : findCompressorStreamProviders())
{
                     putAll(provider.getInputStreamCompressorNames(), provider, map);
                 }
                 return map;
@@ -229,9 +229,9 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
         return AccessController.doPrivileged(new PrivilegedAction<SortedMap<String,
CompressorStreamProvider>>() {
             @Override
             public SortedMap<String, CompressorStreamProvider> run() {
-                TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
+                final TreeMap<String, CompressorStreamProvider> map = new TreeMap<>();
                 putAll(SINGLETON.getOutputStreamCompressorNames(), SINGLETON, map);
-                for (CompressorStreamProvider provider : findCompressorStreamProviders())
{
+                for (final CompressorStreamProvider provider : findCompressorStreamProviders())
{
                     putAll(provider.getOutputStreamCompressorNames(), provider, map);
                 }
                 return map;
@@ -283,9 +283,9 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
         return Z;
     }
 
-    static void putAll(Set<String> names, CompressorStreamProvider provider,
-            TreeMap<String, CompressorStreamProvider> map) {
-        for (String name : names) {
+    static void putAll(final Set<String> names, final CompressorStreamProvider provider,
+            final TreeMap<String, CompressorStreamProvider> map) {
+        for (final String name : names) {
             map.put(toKey(name), provider);
         }
     }
@@ -429,9 +429,14 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
      * @throws IllegalArgumentException
      *             if the name or input stream is null
      */
-    @Override
     public CompressorInputStream createCompressorInputStream(final String name, final InputStream
in)
             throws CompressorException {
+        return createCompressorInputStream(name, in, decompressConcatenated);
+    }
+
+    @Override
+    public CompressorInputStream createCompressorInputStream(final String name, final InputStream
in,
+            final boolean actualDecompressConcatenated) throws CompressorException {
         if (name == null || in == null) {
             throw new IllegalArgumentException("Compressor name and stream must not be null.");
         }
@@ -439,15 +444,15 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
         try {
 
             if (GZIP.equalsIgnoreCase(name)) {
-                return new GzipCompressorInputStream(in, decompressConcatenated);
+                return new GzipCompressorInputStream(in, actualDecompressConcatenated);
             }
 
             if (BZIP2.equalsIgnoreCase(name)) {
-                return new BZip2CompressorInputStream(in, decompressConcatenated);
+                return new BZip2CompressorInputStream(in, actualDecompressConcatenated);
             }
 
             if (XZ.equalsIgnoreCase(name)) {
-                return new XZCompressorInputStream(in, decompressConcatenated);
+                return new XZCompressorInputStream(in, actualDecompressConcatenated);
             }
 
             if (LZMA.equalsIgnoreCase(name)) {
@@ -479,7 +484,7 @@ public class CompressorStreamFactory implements CompressorStreamProvider
{
         }
         final CompressorStreamProvider compressorStreamProvider = getCompressorInputStreamProviders().get(toKey(name));
         if (compressorStreamProvider != null) {
-            return compressorStreamProvider.createCompressorInputStream(name, in);
+            return compressorStreamProvider.createCompressorInputStream(name, in, actualDecompressConcatenated);
         }
         
         throw new CompressorException("Compressor: " + name + " not found.");

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/350f01c7/src/main/java/org/apache/commons/compress/compressors/CompressorStreamProvider.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamProvider.java
b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamProvider.java
index 72f28fd..4009cdb 100644
--- a/src/main/java/org/apache/commons/compress/compressors/CompressorStreamProvider.java
+++ b/src/main/java/org/apache/commons/compress/compressors/CompressorStreamProvider.java
@@ -42,13 +42,18 @@ public interface CompressorStreamProvider {
      *            {@value #DEFLATE}
      * @param in
      *            the input stream
+     * @param decompressUntilEOF
+     *            if true, decompress until the end of the input; if false, stop
+     *            after the first stream and leave the input position to point
+     *            to the next byte after the stream. This setting applies to the
+     *            gzip, bzip2 and xz formats only.
      * @return compressor input stream
      * @throws CompressorException
      *             if the compressor name is not known
      * @throws IllegalArgumentException
      *             if the name or input stream is null
      */
-    CompressorInputStream createCompressorInputStream(final String name, final InputStream
in)
+    CompressorInputStream createCompressorInputStream(final String name, final InputStream
in, final boolean decompressUntilEOF)
             throws CompressorException;
 
     /**

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/350f01c7/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
index dc0953f..82ff6e8 100644
--- a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
+++ b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java
@@ -63,7 +63,7 @@ public class CompressorStreamFactoryRoundtripTest {
         compressorOutputStream.flush();
         compressorOutputStream.close();
         final ByteArrayInputStream is = new ByteArrayInputStream(compressedOs.toByteArray());
-        final CompressorInputStream compressorInputStream = factory.createCompressorInputStream(compressorName,
is);
+        final CompressorInputStream compressorInputStream = factory.createCompressorInputStream(compressorName,
is, false);
         final ByteArrayOutputStream decompressedOs = new ByteArrayOutputStream();
         IOUtils.copy(compressorInputStream, decompressedOs);
         compressorInputStream.close();

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/350f01c7/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
b/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
index 52092d2..62d72e9 100644
--- a/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
+++ b/src/test/java/org/apache/commons/compress/compressors/TestCompressorStreamProvider.java
@@ -31,18 +31,19 @@ public class TestCompressorStreamProvider implements CompressorStreamProvider
{
 
         private static final long serialVersionUID = 1L;
 
-        public InvocationConfirmationException(String message) {
+        public InvocationConfirmationException(final String message) {
             super(message);
         }
     }
 
     @Override
-    public CompressorInputStream createCompressorInputStream(String name, InputStream in)
throws CompressorException {
+    public CompressorInputStream createCompressorInputStream(final String name, final InputStream
in,
+            final boolean decompressConcatenated) throws CompressorException {
         throw new InvocationConfirmationException(name);
     }
 
     @Override
-    public CompressorOutputStream createCompressorOutputStream(String name, OutputStream
out)
+    public CompressorOutputStream createCompressorOutputStream(final String name, final OutputStream
out)
             throws CompressorException {
         throw new InvocationConfirmationException(name);
     }


Mime
View raw message