commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1660002 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
Date Sun, 15 Feb 2015 22:49:02 GMT
Author: sebb
Date: Sun Feb 15 22:49:01 2015
New Revision: 1660002

URL: http://svn.apache.org/r1660002
Log:
COMPRESS-303 Restore immutability/thread-safety to CompressorStreamFactory.

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1660002&r1=1660001&r2=1660002&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sun Feb 15 22:49:01 2015
@@ -54,6 +54,11 @@ breaks backwards compatibility for code
 This also changes the superclass of ZCompressorInputStream.    
 ">
 
+      <action issue="COMPRESS-303" type="fix">
+        Restore immutability/thread-safety to CompressorStreamFactory.
+        The class is now immutable provided that the method setDecompressConcatenated is
not used.
+        The class is thread-safe.
+      </action>
       <action issue="COMPRESS-296" type="add" date="2014-01-10"
               due-to="Kristian Rosenvold">
         Added support for parallel compression. This low-level API allows

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java?rev=1660002&r1=1660001&r2=1660002&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
Sun Feb 15 22:49:01 2015
@@ -62,7 +62,7 @@ import org.apache.commons.compress.utils
  * IOUtils.copy(in, new FileOutputStream(output));
  * in.close();
  * </pre>
- * 
+ * @Immutable provided that the deprecated method setDecompressConcatenated is not used.
  */
 public class CompressorStreamFactory {
 
@@ -124,7 +124,44 @@ public class CompressorStreamFactory {
      */
     public static final String DEFLATE = "deflate";
 
-    private boolean decompressConcatenated = false;
+    /**
+     * 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
+     */
+    private final Boolean decompressUntilEOF;
+    // This is Boolean so setDecompressConcatenated can determine whether it has been set
by the ctor
+    // once the setDecompressConcatenated method has been removed, it can revert to boolean
+
+    /**
+     * 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
+     */
+
+    private volatile boolean decompressConcatenated = false;
+
+    /**
+     * Create an instance with the decompress Concatenated option set to false.
+     */
+    public CompressorStreamFactory() {
+        this.decompressUntilEOF = null;  
+    }
+
+    /**
+     * Create an instance with the provided decompress Concatenated option.
+     * @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
+     * @since 1.10
+     */
+    public CompressorStreamFactory(boolean decompressUntilEOF) {
+        this.decompressUntilEOF = Boolean.valueOf(decompressUntilEOF);
+        // Also copy to existing variable so can continue to use that as the current value
+        this.decompressConcatenated = decompressUntilEOF;
+    }
 
     /**
      * Whether to decompress the full input or only the first stream
@@ -138,8 +175,13 @@ public class CompressorStreamFactory {
      *                          stream and leave the input position to point
      *                          to the next byte after the stream
      * @since 1.5
+     * @deprecated 1.10 use the {@link #CompressorStreamFactory(boolean)} constructor instead
      */
+    @Deprecated
     public void setDecompressConcatenated(boolean decompressConcatenated) {
+        if (this.decompressUntilEOF != null) {
+            throw new IllegalStateException("Cannot override the setting defined by the constructor");
+        }
         this.decompressConcatenated = decompressConcatenated;
     }
 



Mime
View raw message