ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject svn commit: r568886 - in /ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools: ant/util/Base64Converter.java zip/AsiExtraField.java
Date Thu, 23 Aug 2007 08:28:54 GMT
Author: peterreilly
Date: Thu Aug 23 01:28:53 2007
New Revision: 568886

URL: http://svn.apache.org/viewvc?rev=568886&view=rev
Log:
sync: more magic numbers

Modified:
    ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/util/Base64Converter.java
    ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/zip/AsiExtraField.java

Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/util/Base64Converter.java
URL: http://svn.apache.org/viewvc/ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/util/Base64Converter.java?rev=568886&r1=568885&r2=568886&view=diff
==============================================================================
--- ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/util/Base64Converter.java
(original)
+++ ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/ant/util/Base64Converter.java
Thu Aug 23 01:28:53 2007
@@ -26,6 +26,11 @@
 public class Base64Converter {
 
     private static final int BYTE_MASK = 0xFF;
+    private static final int POS_0_MASK = 0x0000003F;
+    private static final int POS_1_MASK = 0x00000FC0;
+    private static final int POS_2_MASK = 0x0003F000;
+    private static final int POS_3_MASK = 0x00FC0000;
+
 
     private static final char[] ALPHABET = {
         'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',  //  0 to  7
@@ -71,24 +76,24 @@
             bits24 |= (octetString[i++] & BYTE_MASK) << 8;
             bits24 |= octetString[i++];
 
-            bits6 = (bits24 & 0x00FC0000) >> 18;
+            bits6 = (bits24 & POS_3_MASK) >> 18;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & 0x0003F000) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> 12;
             out[outIndex++] = ALPHABET[bits6];
-            bits6  = (bits24 & 0x00000FC0) >> 6;
+            bits6  = (bits24 & POS_1_MASK) >> 6;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & 0x0000003F);
+            bits6 = (bits24 & POS_0_MASK);
             out[outIndex++] = ALPHABET[bits6];
         }
         if (octetString.length - i == 2) {
             // store the octets
             bits24 = (octetString[i] & BYTE_MASK) << 16;
             bits24 |= (octetString[i + 1] & BYTE_MASK) << 8;
-            bits6 = (bits24 & 0x00FC0000) >> 18;
+            bits6 = (bits24 & POS_3_MASK) >> 18;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & 0x0003F000) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> 12;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & 0x00000FC0) >> 6;
+            bits6 = (bits24 & POS_1_MASK) >> 6;
             out[outIndex++] = ALPHABET[bits6];
 
             // padding
@@ -96,9 +101,9 @@
         } else if (octetString.length - i == 1) {
             // store the octets
             bits24 = (octetString[i] & BYTE_MASK) << 16;
-            bits6 = (bits24 & 0x00FC0000) >> 18;
+            bits6 = (bits24 & POS_3_MASK) >> 18;
             out[outIndex++] = ALPHABET[bits6];
-            bits6 = (bits24 & 0x0003F000) >> 12;
+            bits6 = (bits24 & POS_2_MASK) >> 12;
             out[outIndex++] = ALPHABET[bits6];
 
             // padding

Modified: ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/zip/AsiExtraField.java
URL: http://svn.apache.org/viewvc/ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/zip/AsiExtraField.java?rev=568886&r1=568885&r2=568886&view=diff
==============================================================================
--- ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/zip/AsiExtraField.java (original)
+++ ant/core/branches/ANT_17_BRANCH/src/main/org/apache/tools/zip/AsiExtraField.java Thu Aug
23 01:28:53 2007
@@ -49,7 +49,7 @@
 public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable {
 
     private static final ZipShort HEADER_ID = new ZipShort(0x756E);
-
+    private static final int      WORD = 4;
     /**
      * Standard Unix stat(2) file mode.
      *
@@ -110,9 +110,9 @@
      * @since 1.1
      */
     public ZipShort getLocalFileDataLength() {
-        return new ZipShort(4         // CRC
+        return new ZipShort(WORD         // CRC
                           + 2         // Mode
-                          + 4         // SizDev
+                          + WORD         // SizDev
                           + 2         // UID
                           + 2         // GID
                           + getLinkedFile().getBytes().length);
@@ -135,12 +135,12 @@
      */
     public byte[] getLocalFileDataData() {
         // CRC will be added later
-        byte[] data = new byte[getLocalFileDataLength().getValue() - 4];
+        byte[] data = new byte[getLocalFileDataLength().getValue() - WORD];
         System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2);
 
         byte[] linkArray = getLinkedFile().getBytes();
         System.arraycopy(ZipLong.getBytes(linkArray.length),
-                         0, data, 2, 4);
+                         0, data, 2, WORD);
 
         System.arraycopy(ZipShort.getBytes(getUserId()),
                          0, data, 6, 2);
@@ -153,9 +153,9 @@
         crc.update(data);
         long checksum = crc.getValue();
 
-        byte[] result = new byte[data.length + 4];
-        System.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, 4);
-        System.arraycopy(data, 0, result, 4, data.length);
+        byte[] result = new byte[data.length + WORD];
+        System.arraycopy(ZipLong.getBytes(checksum), 0, result, 0, WORD);
+        System.arraycopy(data, 0, result, WORD, data.length);
         return result;
     }
 
@@ -287,8 +287,8 @@
         throws ZipException {
 
         long givenChecksum = ZipLong.getValue(data, offset);
-        byte[] tmp = new byte[length - 4];
-        System.arraycopy(data, offset + 4, tmp, 0, length - 4);
+        byte[] tmp = new byte[length - WORD];
+        System.arraycopy(data, offset + WORD, tmp, 0, length - WORD);
         crc.reset();
         crc.update(tmp);
         long realChecksum = crc.getValue();



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message