Author: bodewig
Date: Fri Oct 11 08:12:36 2013
New Revision: 1531219

URL: http://svn.apache.org/r1531219
Log:
add an enum for 7z compression methods, early preparations for compressed write 
support

Added:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
   (with props)
Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/Coders.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=1531219&r1=1531218&r2=1531219&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
 Fri Oct 11 08:12:36 2013
@@ -41,7 +41,7 @@ class Coders {
     static InputStream addDecoder(final InputStream is,
             final Coder coder, final String password) throws IOException {
         for (final CoderId coderId : coderTable) {
-            if (Arrays.equals(coderId.id, coder.decompressionMethodId)) {
+            if (Arrays.equals(coderId.method.getId(), 
coder.decompressionMethodId)) {
                 return coderId.coder.decode(is, coder, password);
             }
         }
@@ -50,21 +50,21 @@ class Coders {
     }
     
     static CoderId[] coderTable = new CoderId[] {
-        new CoderId(new byte[] { (byte)0x00 }, new CopyDecoder()),
-        new CoderId(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }, new 
LZMADecoder()),
-        new CoderId(new byte[] { (byte)0x21 }, new LZMA2Decoder()),
-        new CoderId(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }, new 
DeflateDecoder()),
-        new CoderId(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }, new 
BZIP2Decoder()),
-        new CoderId(new byte[] { (byte)0x06, (byte)0xf1, (byte)0x07, 
(byte)0x01 }, new AES256SHA256Decoder())
+        new CoderId(SevenZMethod.COPY, new CopyDecoder()),
+        new CoderId(SevenZMethod.LZMA, new LZMADecoder()),
+        new CoderId(SevenZMethod.LZMA2, new LZMA2Decoder()),
+        new CoderId(SevenZMethod.DEFLATE, new DeflateDecoder()),
+        new CoderId(SevenZMethod.BZIP2, new BZIP2Decoder()),
+        new CoderId(SevenZMethod.AES256SHA256, new AES256SHA256Decoder())
     };
     
     static class CoderId {
-        CoderId(final byte[] id, final CoderBase coder) {
-            this.id = id;
+        CoderId(SevenZMethod method, final CoderBase coder) {
+            this.method = method;
             this.coder = coder;
         }
 
-        final byte[] id;
+        final SevenZMethod method;
         final CoderBase coder;
     }
     

Added: 
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=1531219&view=auto
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
 (added)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
 Fri Oct 11 08:12:36 2013
@@ -0,0 +1,52 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.commons.compress.archivers.sevenz;
+
+/**
+ * The (partially) supported compression/encryption methods used in 7z 
archives.
+ */
+public enum SevenZMethod {
+    /** no compression at all */
+    COPY(new byte[] { (byte)0x00 }),
+    /** LZMA - only supported when reading */
+    LZMA(new byte[] { (byte)0x03, (byte)0x01, (byte)0x01 }),
+    /** LZMA2 - only supported when reading */
+    LZMA2(new byte[] { (byte)0x21 }),
+    /** Deflate - only supported when reading */
+    DEFLATE(new byte[] { (byte)0x04, (byte)0x01, (byte)0x08 }),
+    /** BZIP2 - only supported when reading */
+    BZIP2(new byte[] { (byte)0x04, (byte)0x02, (byte)0x02 }),
+    /**
+     * AES encryption with a key length of 256 bit using SHA256 for
+     * hashes - only supported when reading
+     */
+    AES256SHA256(new byte[] { (byte)0x06, (byte)0xf1, (byte)0x07, (byte)0x01 
});
+
+    private final byte[] id;
+
+    private SevenZMethod(byte[] id) {
+        this.id = id;
+    }
+
+    byte[] getId() {
+        byte[] copy = new byte[id.length];
+        System.arraycopy(id, 0, copy, 0, id.length);
+        return copy;
+    }
+
+}

Propchange: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to