Author: bodewig
Date: Fri Jan  9 17:58:15 2015
New Revision: 1650615

URL: http://svn.apache.org/r1650615
Log:
replace a few magic numbers with constants

Modified:
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java?rev=1650615&r1=1650614&r2=1650615&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ParallelScatterZipCreator.java
 Fri Jan  9 17:58:15 2015
@@ -116,7 +116,9 @@ public class ParallelScatterZipCreator {
 
     public void addArchiveEntry(final ZipArchiveEntry zipArchiveEntry, final 
InputStreamSupplier source) {
         final int method = zipArchiveEntry.getMethod();
-        if (method == -1) throw new IllegalArgumentException("Method must be 
set on the supplied zipArchiveEntry");
+        if (method == ZipMethod.UNKNOWN_CODE) {
+            throw new IllegalArgumentException("Method must be set on the 
supplied zipArchiveEntry");
+        }
         // Consider if we want to constrain the number of items that can 
enqueue here.
         es.submit(new Callable<ScatterZipOutputStream>() {
             public ScatterZipOutputStream call() throws Exception {

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1650615&r1=1650614&r2=1650615&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
 Fri Jan  9 17:58:15 2015
@@ -53,6 +53,7 @@ public class ZipArchiveEntry extends jav
 
     public static final int PLATFORM_UNIX = 3;
     public static final int PLATFORM_FAT  = 0;
+    public static final int CRC_UNKNOWN = -1;
     private static final int SHORT_MASK = 0xFFFF;
     private static final int SHORT_SHIFT = 16;
     private static final byte[] EMPTY = new byte[0];
@@ -67,7 +68,7 @@ public class ZipArchiveEntry extends jav
      * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-93";
      *        >COMPRESS-93</a>
      */
-    private int method = -1;
+    private int method = ZipMethod.UNKNOWN_CODE;
 
     /**
      * The {@link java.util.zip.ZipEntry#setSize} method in the base

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=1650615&r1=1650614&r2=1650615&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 Fri Jan  9 17:58:15 2015
@@ -274,7 +274,7 @@ public class ZipArchiveInputStream exten
 
         processZip64Extra(size, cSize);
 
-        if (current.entry.getCompressedSize() != -1) {
+        if (current.entry.getCompressedSize() != ZipArchiveEntry.SIZE_UNKNOWN) 
{
             if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()) {
                 current.in = new UnshrinkingInputStream(new 
BoundedInputStream(in, current.entry.getCompressedSize()));
             } else if (current.entry.getMethod() == 
ZipMethod.IMPLODING.getCode()) {

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1650615&r1=1650614&r2=1650615&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
 Fri Jan  9 17:58:15 2015
@@ -545,9 +545,9 @@ public class ZipArchiveOutputStream exte
             // since standard mode is unable to remove the zip 64 header.
             ae.removeExtraField(Zip64ExtendedInformationExtraField.HEADER_ID);
         }
-        boolean is2PhaseSource = ae.getCrc() != -1
+        boolean is2PhaseSource = ae.getCrc() != ZipArchiveEntry.CRC_UNKNOWN
                 && ae.getSize() != ArchiveEntry.SIZE_UNKNOWN
-                && ae.getCompressedSize() != -1;
+                && ae.getCompressedSize() != ArchiveEntry.SIZE_UNKNOWN;
         putArchiveEntry(ae, is2PhaseSource);
         copyFromZipInputStream(rawStream);
         closeCopiedEntry(is2PhaseSource);
@@ -778,7 +778,7 @@ public class ZipArchiveOutputStream exte
                                        + " STORED method when not writing to a"
                                        + " file");
             }
-            if (entry.entry.getCrc() == -1) {
+            if (entry.entry.getCrc() == ZipArchiveEntry.CRC_UNKNOWN) {
                 throw new ZipException("crc checksum is required for STORED"
                                        + " method when not writing to a file");
             }

Modified: 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
URL: 
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java?rev=1650615&r1=1650614&r2=1650615&view=diff
==============================================================================
--- 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
 (original)
+++ 
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
 Fri Jan  9 17:58:15 2015
@@ -164,7 +164,9 @@ public enum ZipMethod {
     /**
      * Unknown compression method.
      */
-    UNKNOWN(-1);
+    UNKNOWN();
+
+    static final int UNKNOWN_CODE = -1;
 
     private final int code;
 
@@ -178,6 +180,10 @@ public enum ZipMethod {
         codeToEnum = Collections.unmodifiableMap(cte);
     }
 
+    private ZipMethod() {
+        this(UNKNOWN_CODE);
+    }
+
     /**
      * private constructor for enum style class.
      */


Reply via email to