Author: bodewig
Date: Sun Feb 23 21:13:58 2014
New Revision: 1571091

URL: http://svn.apache.org/r1571091
Log:
COMPRESS-266 now you can set options for 7z methods, still need to write docs 
and tests

Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java

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=1571091&r1=1571090&r2=1571091&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
 Sun Feb 23 21:13:58 2014
@@ -31,6 +31,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.LinkedList;
+import java.util.Map.Entry;
 import java.util.zip.CRC32;
 
 import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -49,7 +50,8 @@ public class SevenZOutputFile implements
     private long fileBytesWritten = 0;
     private boolean finished = false;
     private CountingOutputStream currentOutputStream;
-    private Iterable<SevenZMethod> contentMethods = 
Collections.singletonList(SevenZMethod.LZMA2);
+    private Iterable<? extends Entry<SevenZMethod, ?>> contentMethods =
+            Collections.singletonList(new FakeEntry(SevenZMethod.LZMA2));
     
     /**
      * Opens file to write a 7z archive to.
@@ -74,7 +76,7 @@ public class SevenZOutputFile implements
      * to {@link #setContentMethods}.</p>
      */
     public void setContentCompression(SevenZMethod method) {
-        setContentMethods(Collections.singletonList(method));
+        setContentMethods(Collections.singletonList(new FakeEntry(method)));
     }
 
     /**
@@ -90,7 +92,7 @@ public class SevenZOutputFile implements
      *
      * @since 1.8
      */
-    public void setContentMethods(Iterable<SevenZMethod> methods) {
+    public void setContentMethods(Iterable<? extends Entry<SevenZMethod, ?>> 
methods) {
         this.contentMethods = methods;
     }
 
@@ -260,8 +262,8 @@ public class SevenZOutputFile implements
 
     private CountingOutputStream setupFileOutputStream() throws IOException {
         OutputStream out = new OutputStreamWrapper();
-        for (SevenZMethod m : reverse(contentMethods)) {
-            out = Coders.addEncoder(out, m, null);
+        for (Entry<SevenZMethod, ?> m : reverse(contentMethods)) {
+            out = Coders.addEncoder(out, m.getKey(), m.getValue());
         }
         return new CountingOutputStream(out) {
             @Override
@@ -368,7 +370,7 @@ public class SevenZOutputFile implements
     private void writeFolder(final DataOutput header) throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
         int numCoders = 0;
-        for (SevenZMethod m : contentMethods) {
+        for (Entry<SevenZMethod, ?> m : contentMethods) {
             numCoders++;
             writeSingleCodec(m, bos);
         }
@@ -377,9 +379,9 @@ public class SevenZOutputFile implements
         header.write(bos.toByteArray());
     }
 
-    private void writeSingleCodec(SevenZMethod m, OutputStream bos) throws 
IOException {
-        byte[] id = m.getId();
-        byte[] properties = m.getProperties(null);
+    private void writeSingleCodec(Entry<SevenZMethod, ?> m, OutputStream bos) 
throws IOException {
+        byte[] id = m.getKey().getId();
+        byte[] properties = m.getKey().getProperties(m.getValue());
 
         int codecFlags = id.length;
         if (properties.length > 0) {
@@ -719,4 +721,20 @@ public class SevenZOutputFile implements
             // the file will be closed by the containing class's close method
         }
     }
+
+    private static class FakeEntry implements Entry<SevenZMethod, Object> {
+        private final SevenZMethod m;
+        FakeEntry(SevenZMethod m) {
+            this.m = m;
+        }
+        public SevenZMethod getKey() {
+            return m;
+        }
+        public Object getValue() {
+            return null;
+        }
+        public Object setValue(Object o) {
+            return null;
+        }
+    }
 }


Reply via email to