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 2014/02/26 06:05:54 UTC

svn commit: r1571923 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java

Author: bodewig
Date: Wed Feb 26 05:05:53 2014
New Revision: 1571923

URL: http://svn.apache.org/r1571923
Log:
COMPRESS-261 allow content compression to be overriden per entry

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.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=1571923&r1=1571922&r2=1571923&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Wed Feb 26 05:05:53 2014
@@ -89,6 +89,10 @@ The <action> type attribute can be add,u
         compression/encryption/filter methods and passing options to
         the methods.
       </action>
+      <action issue="COMPRESS-261" type="add" date="2014-02-26">
+        The (compression) method(s) can now be specified per entry in
+        SevenZOutputFile.
+      </action>
     </release>
     <release version="1.7" date="2014-01-20"
              description="Release 1.7">

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java?rev=1571923&r1=1571922&r2=1571923&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZArchiveEntry.java Wed Feb 26 05:05:53 2014
@@ -18,7 +18,9 @@
 package org.apache.commons.compress.archivers.sevenz;
 
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
+import java.util.LinkedList;
 import java.util.TimeZone;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -45,6 +47,7 @@ public class SevenZArchiveEntry implemen
     private boolean hasCrc;
     private long crc, compressedCrc;
     private long size, compressedSize;
+    private Iterable<? extends SevenZMethodConfiguration> contentMethods;
     
     public SevenZArchiveEntry() {
     }
@@ -406,6 +409,44 @@ public class SevenZArchiveEntry implemen
     }
 
     /**
+     * Sets the (compression) methods to use for entry's content - the
+     * default is LZMA2.
+     *
+     * <p>Currently only {@link SevenZMethod#COPY}, {@link
+     * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link
+     * SevenZMethod#DEFLATE} are supported.</p>
+     *
+     * <p>The methods will be consulted in iteration order to create
+     * the final output.</p>
+     *
+     * @since 1.8
+     */
+    public void setContentMethods(Iterable<? extends SevenZMethodConfiguration> methods) {
+        LinkedList<SevenZMethodConfiguration> l = new LinkedList<SevenZMethodConfiguration>();
+        for (SevenZMethodConfiguration m : methods) {
+            l.addLast(m);
+        }
+        this.contentMethods = Collections.unmodifiableList(l);
+    }
+
+    /**
+     * Gets the (compression) methods to use for entry's content - the
+     * default is LZMA2.
+     *
+     * <p>Currently only {@link SevenZMethod#COPY}, {@link
+     * SevenZMethod#LZMA2}, {@link SevenZMethod#BZIP2} and {@link
+     * SevenZMethod#DEFLATE} are supported.</p>
+     *
+     * <p>The methods will be consulted in iteration order to create
+     * the final output.</p>
+     *
+     * @since 1.8
+     */
+    public Iterable<? extends SevenZMethodConfiguration> getContentMethods() {
+        return contentMethods;
+    }
+
+    /**
      * Converts NTFS time (100 nanosecond units since 1 January 1601)
      * to Java time.
      * @param ntfsTime the NTFS time in 100 nanosecond units

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java?rev=1571923&r1=1571922&r2=1571923&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java Wed Feb 26 05:05:53 2014
@@ -69,7 +69,7 @@ public class SevenZOutputFile implements
     }
     
     /**
-     * Sets the compression method to use for entry contents - the
+     * Sets the default compression method to use for entry contents - the
      * default is LZMA2.
      *
      * <p>Currently only {@link SevenZMethod#COPY}, {@link
@@ -84,7 +84,7 @@ public class SevenZOutputFile implements
     }
 
     /**
-     * Sets the (compression) methods to use for entry contents - the
+     * Sets the default (compression) methods to use for entry contents - the
      * default is LZMA2.
      *
      * <p>Currently only {@link SevenZMethod#COPY}, {@link
@@ -276,7 +276,7 @@ public class SevenZOutputFile implements
         OutputStream out = new OutputStreamWrapper();
         ArrayList<CountingOutputStream> moreStreams = new ArrayList<CountingOutputStream>();
         boolean first = true;
-        for (SevenZMethodConfiguration m : contentMethods) {
+        for (SevenZMethodConfiguration m : getContentMethods(files.get(files.size() - 1))) {
             if (!first) {
                 CountingOutputStream cos = new CountingOutputStream(out);
                 moreStreams.add(cos);
@@ -318,6 +318,11 @@ public class SevenZOutputFile implements
         return l;
     }
 
+    private Iterable<? extends SevenZMethodConfiguration> getContentMethods(SevenZArchiveEntry entry) {
+        Iterable<? extends SevenZMethodConfiguration> ms = entry.getContentMethods();
+        return ms == null ? contentMethods : ms;
+    }
+
     private void writeHeader(final DataOutput header) throws IOException {
         header.write(NID.kHeader);
         
@@ -368,10 +373,12 @@ public class SevenZOutputFile implements
         header.write(NID.kFolder);
         writeUint64(header, numNonEmptyStreams);
         header.write(0);
-        for (int i = 0; i < numNonEmptyStreams; i++) {
-            writeFolder(header);
+        for (SevenZArchiveEntry entry : files) {
+            if (entry.hasStream()) {
+                writeFolder(header, entry);
+            }
         }
-        
+
         header.write(NID.kCodersUnpackSize);
         for (final SevenZArchiveEntry entry : files) {
             if (entry.hasStream()) {
@@ -396,10 +403,10 @@ public class SevenZOutputFile implements
         header.write(NID.kEnd);
     }
     
-    private void writeFolder(final DataOutput header) throws IOException {
+    private void writeFolder(final DataOutput header, SevenZArchiveEntry entry) throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         int numCoders = 0;
-        for (SevenZMethodConfiguration m : contentMethods) {
+        for (SevenZMethodConfiguration m : getContentMethods(entry)) {
             numCoders++;
             writeSingleCodec(m, bos);
         }