commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1571243 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz: Coders.java LZMA2Decoder.java SevenZMethod.java SevenZOutputFile.java
Date Mon, 24 Feb 2014 11:15:57 GMT
Author: bodewig
Date: Mon Feb 24 11:15:56 2014
New Revision: 1571243

URL: http://svn.apache.org/r1571243
Log:
keep options <=> properties translations in a single place, the Codec

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMA2Decoder.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
    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/Coders.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java?rev=1571243&r1=1571242&r2=1571243&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.java
Mon Feb 24 11:15:56 2014
@@ -91,6 +91,7 @@ class Coders {
     
     static abstract class CoderBase {
         private final Class<?>[] acceptableOptions;
+        private static final byte[] NONE = new byte[0];
 
         protected CoderBase(Class<?>... acceptableOptions) {
             this.acceptableOptions = acceptableOptions;
@@ -108,6 +109,13 @@ class Coders {
             return false;
         }
 
+        /**
+         * @return property-bytes to write in a Folder block
+         */
+        byte[] getOptionsAsProperties(Object options) {
+            return NONE;
+        }
+
         abstract InputStream decode(final InputStream in, final Coder coder,
                 byte[] password) throws IOException;
         OutputStream encode(final OutputStream out, final Object options)

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMA2Decoder.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMA2Decoder.java?rev=1571243&r1=1571242&r2=1571243&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMA2Decoder.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/LZMA2Decoder.java
Mon Feb 24 11:15:56 2014
@@ -57,6 +57,23 @@ class LZMA2Decoder extends Coders.CoderB
         return options.getOutputStream(wrapped);
     }
 
+    @Override
+    byte[] getOptionsAsProperties(Object opts) {
+        int dictSize = getDictSize(opts);
+        int lead = Integer.numberOfLeadingZeros(dictSize);
+        int secondBit = (dictSize >>> (30 - lead)) - 2;
+        return new byte[] {
+            (byte) ((19 - lead) * 2 + secondBit)
+        };
+    }
+
+    private int getDictSize(Object opts) {
+        if (opts instanceof LZMA2Options) {
+            return ((LZMA2Options) opts).getDictSize();
+        }
+        return LZMA2Options.DICT_SIZE_DEFAULT;
+    }
+
     private LZMA2Options getOptions(Object opts) throws IOException {
         if (opts instanceof LZMA2Options) {
             return (LZMA2Options) opts;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java?rev=1571243&r1=1571242&r2=1571243&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
Mon Feb 24 11:15:56 2014
@@ -17,8 +17,6 @@
  */
 package org.apache.commons.compress.archivers.sevenz;
 
-import org.tukaani.xz.LZMA2Options;
-
 /**
  * The (partially) supported compression/encryption methods used in 7z archives.
  */
@@ -28,23 +26,7 @@ public enum SevenZMethod {
     /** LZMA - only supported when reading */
     LZMA(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }),
     /** LZMA2 */
-    LZMA2(new byte[] { (byte)0x21 }) {
-        @Override
-        byte[] getProperties(Object opts) {
-            int dictSize = getDictSize(opts);
-            int lead = Integer.numberOfLeadingZeros(dictSize);
-            int secondBit = (dictSize >>> (30 - lead)) - 2;
-            return new byte[] {
-                (byte) ((19 - lead) * 2 + secondBit)
-            };
-        }
-        private int getDictSize(Object opts) {
-            if (opts instanceof LZMA2Options) {
-                return ((LZMA2Options) opts).getDictSize();
-            }
-            return LZMA2Options.DICT_SIZE_DEFAULT;
-        }
-    },
+    LZMA2(new byte[] { (byte)0x21 }),
     /** Deflate */
     DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }),
     /** BZIP2 */
@@ -67,11 +49,4 @@ public enum SevenZMethod {
         return copy;
     }
 
-    /**
-     * @param opts options requested for the given entry
-     */
-    byte[] getProperties(Object opts) {
-        return new byte[0];
-    }
-
 }

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=1571243&r1=1571242&r2=1571243&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
Mon Feb 24 11:15:56 2014
@@ -380,7 +380,8 @@ public class SevenZOutputFile implements
 
     private void writeSingleCodec(SevenZMethodConfiguration m, OutputStream bos) throws IOException
{
         byte[] id = m.getMethod().getId();
-        byte[] properties = m.getMethod().getProperties(m.getOptions());
+        byte[] properties = Coders.findByMethod(m.getMethod())
+            .getOptionsAsProperties(m.getOptions());
 
         int codecFlags = id.length;
         if (properties.length > 0) {



Mime
View raw message