commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1692045 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/zip/UnshrinkingInputStream.java compressors/lzw/LZWInputStream.java compressors/z/ZCompressorInputStream.java
Date Tue, 21 Jul 2015 04:14:01 GMT
Author: bodewig
Date: Tue Jul 21 04:14:00 2015
New Revision: 1692045

URL: http://svn.apache.org/r1692045
Log:
committed local change by accident

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java?rev=1692045&r1=1692044&r2=1692045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/UnshrinkingInputStream.java
Tue Jul 21 04:14:00 2015
@@ -36,22 +36,20 @@ class UnshrinkingInputStream extends LZW
     
     public UnshrinkingInputStream(InputStream inputStream) throws IOException {
         super(inputStream, ByteOrder.LITTLE_ENDIAN);
-        setClearCode(DEFAULT_CODE_SIZE);
+        setClearCode(codeSize);
         initializeTables(MAX_CODE_SIZE);
-        isUsed = new boolean[getPrefixesLength()];
+        isUsed = new boolean[prefixes.length];
         for (int i = 0; i < (1 << 8); i++) {
             isUsed[i] = true;
         }
-        setTableSize(getClearCode() + 1);
+        tableSize = clearCode + 1;
     }
 
     @Override
     protected int addEntry(int previousCode, byte character) throws IOException {
-        int tableSize = getTableSize();
         while ((tableSize < MAX_TABLE_SIZE) && isUsed[tableSize]) {
             tableSize++;
         }
-        setTableSize(tableSize);
         int idx = addEntry(previousCode, character, MAX_TABLE_SIZE);
         if (idx >= 0) {
             isUsed[idx] = true;
@@ -62,14 +60,14 @@ class UnshrinkingInputStream extends LZW
     private void partialClear() {
         final boolean[] isParent = new boolean[MAX_TABLE_SIZE];
         for (int i = 0; i < isUsed.length; i++) {
-            if (isUsed[i] && getPrefix(i) != UNUSED_PREFIX) {
-                isParent[getPrefix(i)] = true;
+            if (isUsed[i] && prefixes[i] != -1) {
+                isParent[prefixes[i]] = true;
             }
         }
-        for (int i = getClearCode() + 1; i < isParent.length; i++) {
+        for (int i = clearCode + 1; i < isParent.length; i++) {
             if (!isParent[i]) {
                 isUsed[i] = false;
-                setPrefix(i, UNUSED_PREFIX);
+                prefixes[i] = -1;
             }
         }
     }
@@ -91,19 +89,19 @@ class UnshrinkingInputStream extends LZW
         final int code = readNextCode();
         if (code < 0) {
             return -1;
-        } else if (code == getClearCode()) {
+        } else if (code == clearCode) {
             final int subCode = readNextCode();
             if (subCode < 0) {
                 throw new IOException("Unexpected EOF;");
             } else if (subCode == 1) {
-                if (getCodeSize() < MAX_CODE_SIZE) {
-                    incrementCodeSize();
+                if (codeSize < MAX_CODE_SIZE) {
+                    codeSize++;
                 } else {
                     throw new IOException("Attempt to increase code size beyond maximum");
                 }
             } else if (subCode == 2) {
                 partialClear();
-                setTableSize(getClearCode() + 1);
+                tableSize = clearCode + 1;
             } else {
                 throw new IOException("Invalid clear code subcode " + subCode);
             }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java?rev=1692045&r1=1692044&r2=1692045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/lzw/LZWInputStream.java
Tue Jul 21 04:14:00 2015
@@ -34,19 +34,16 @@ import org.apache.commons.compress.utils
  * @since 1.10
  */
 public abstract class LZWInputStream extends CompressorInputStream {
-    protected static final int DEFAULT_CODE_SIZE = 9;
-    protected static final int UNUSED_PREFIX = -1;
-
     private final byte[] oneByte = new byte[1];
 
     protected final BitInputStream in;
-    private int clearCode = -1;
-    private int codeSize = DEFAULT_CODE_SIZE;
-    private byte previousCodeFirstChar;
-    private int previousCode = UNUSED_PREFIX;
-    private int tableSize;
-    private int[] prefixes;
-    private byte[] characters;
+    protected int clearCode = -1;
+    protected int codeSize = 9;
+    protected byte previousCodeFirstChar;
+    protected int previousCode = -1;
+    protected int tableSize = 0;
+    protected int[] prefixes;
+    protected byte[] characters;
     private byte[] outputStack;
     private int outputStackLocation;
 
@@ -181,60 +178,4 @@ public abstract class LZWInputStream ext
         }
         return 0;
     }
-
-    protected int getCodeSize() {
-        return codeSize;
-    }
-
-    protected void resetCodeSize() {
-        this.codeSize = DEFAULT_CODE_SIZE;
-    }
-
-    protected void incrementCodeSize() {
-        codeSize++;
-    }
-
-    protected int getPreviousCode() {
-        return previousCode;
-    }
-
-    protected byte getPreviousCodeFirstChar() {
-        return previousCodeFirstChar;
-    }
-
-    protected void resetPreviousCode() {
-        this.previousCode = -1;
-    }
-
-    protected int getPrefix(int offset) {
-        return prefixes[offset];
-    }
-
-    protected void setPrefix(int offset, int value) {
-        prefixes[offset] = value;
-    }
-
-    protected int getPrefixesLength() {
-        return prefixes.length;
-    }
-
-    protected int getClearCode() {
-        return clearCode;
-    }
-
-    protected int getTableSize() {
-        return tableSize;
-    }
-
-    protected void setTableSize(int newSize) {
-        tableSize = newSize;
-    }
-
-    protected void setCharacter(int offset, byte value) {
-        characters[offset] = value;
-    }
-
-    protected byte getCharacter(int offset) {
-        return characters[offset];
-    }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java?rev=1692045&r1=1692044&r2=1692045&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java
Tue Jul 21 04:14:00 2015
@@ -49,14 +49,17 @@ public class ZCompressorInputStream exte
         blockMode = (thirdByte & BLOCK_MODE_MASK) != 0;
         maxCodeSize = thirdByte & MAX_CODE_SIZE_MASK;
         if (blockMode) {
-            setClearCode(DEFAULT_CODE_SIZE);
+            setClearCode(codeSize);
         }
         initializeTables(maxCodeSize);
         clearEntries();
     }
     
     private void clearEntries() {
-        setTableSize((1 << 8) + (blockMode ? 1 : 0));
+        tableSize = 1 << 8;
+        if (blockMode) {
+            tableSize++;
+        }
     }
 
     /**
@@ -97,11 +100,11 @@ public class ZCompressorInputStream exte
      */
     @Override
     protected int addEntry(int previousCode, byte character) throws IOException {
-        final int maxTableSize = 1 << getCodeSize();
+        final int maxTableSize = 1 << codeSize;
         int r = addEntry(previousCode, character, maxTableSize);
-        if (getTableSize() == maxTableSize && getCodeSize() < maxCodeSize) {
+        if (tableSize == maxTableSize && codeSize < maxCodeSize) {
             reAlignReading();
-            incrementCodeSize();
+            codeSize++;
         }
         return r;
     }
@@ -129,19 +132,19 @@ public class ZCompressorInputStream exte
         final int code = readNextCode();
         if (code < 0) {
             return -1;
-        } else if (blockMode && code == getClearCode()) {
+        } else if (blockMode && code == clearCode) {
             clearEntries();
             reAlignReading();
-            resetCodeSize();
-            resetPreviousCode();
+            codeSize = 9;
+            previousCode = -1;
             return 0;
         } else {
             boolean addedUnfinishedEntry = false;
-            if (code == getTableSize()) {
+            if (code == tableSize) {
                 addRepeatOfPreviousCode();
                 addedUnfinishedEntry = true;
-            } else if (code > getTableSize()) {
-                throw new IOException(String.format("Invalid %d bit code 0x%x", getCodeSize(),
code));
+            } else if (code > tableSize) {
+                throw new IOException(String.format("Invalid %d bit code 0x%x", codeSize,
code));
             }
             return expandCodeToOutputStack(code, addedUnfinishedEntry);
         }



Mime
View raw message