git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@568885 13f79535-47bb-0310-9956-ffa450edef68master
@@ -26,6 +26,11 @@ package org.apache.tools.ant.util; | |||||
public class Base64Converter { | public class Base64Converter { | ||||
private static final int BYTE_MASK = 0xFF; | 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 = { | private static final char[] ALPHABET = { | ||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7 | ||||
@@ -71,24 +76,24 @@ public class Base64Converter { | |||||
bits24 |= (octetString[i++] & BYTE_MASK) << 8; | bits24 |= (octetString[i++] & BYTE_MASK) << 8; | ||||
bits24 |= octetString[i++]; | bits24 |= octetString[i++]; | ||||
bits6 = (bits24 & 0x00FC0000) >> 18; | |||||
bits6 = (bits24 & POS_3_MASK) >> 18; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x0003F000) >> 12; | |||||
bits6 = (bits24 & POS_2_MASK) >> 12; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x00000FC0) >> 6; | |||||
bits6 = (bits24 & POS_1_MASK) >> 6; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x0000003F); | |||||
bits6 = (bits24 & POS_0_MASK); | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
} | } | ||||
if (octetString.length - i == 2) { | if (octetString.length - i == 2) { | ||||
// store the octets | // store the octets | ||||
bits24 = (octetString[i] & BYTE_MASK) << 16; | bits24 = (octetString[i] & BYTE_MASK) << 16; | ||||
bits24 |= (octetString[i + 1] & BYTE_MASK) << 8; | bits24 |= (octetString[i + 1] & BYTE_MASK) << 8; | ||||
bits6 = (bits24 & 0x00FC0000) >> 18; | |||||
bits6 = (bits24 & POS_3_MASK) >> 18; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x0003F000) >> 12; | |||||
bits6 = (bits24 & POS_2_MASK) >> 12; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x00000FC0) >> 6; | |||||
bits6 = (bits24 & POS_1_MASK) >> 6; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
// padding | // padding | ||||
@@ -96,9 +101,9 @@ public class Base64Converter { | |||||
} else if (octetString.length - i == 1) { | } else if (octetString.length - i == 1) { | ||||
// store the octets | // store the octets | ||||
bits24 = (octetString[i] & BYTE_MASK) << 16; | bits24 = (octetString[i] & BYTE_MASK) << 16; | ||||
bits6 = (bits24 & 0x00FC0000) >> 18; | |||||
bits6 = (bits24 & POS_3_MASK) >> 18; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
bits6 = (bits24 & 0x0003F000) >> 12; | |||||
bits6 = (bits24 & POS_2_MASK) >> 12; | |||||
out[outIndex++] = ALPHABET[bits6]; | out[outIndex++] = ALPHABET[bits6]; | ||||
// padding | // padding | ||||
@@ -49,7 +49,7 @@ import java.util.zip.ZipException; | |||||
public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | ||||
private static final ZipShort HEADER_ID = new ZipShort(0x756E); | private static final ZipShort HEADER_ID = new ZipShort(0x756E); | ||||
private static final int WORD = 4; | |||||
/** | /** | ||||
* Standard Unix stat(2) file mode. | * Standard Unix stat(2) file mode. | ||||
* | * | ||||
@@ -110,9 +110,9 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | |||||
* @since 1.1 | * @since 1.1 | ||||
*/ | */ | ||||
public ZipShort getLocalFileDataLength() { | public ZipShort getLocalFileDataLength() { | ||||
return new ZipShort(4 // CRC | |||||
return new ZipShort(WORD // CRC | |||||
+ 2 // Mode | + 2 // Mode | ||||
+ 4 // SizDev | |||||
+ WORD // SizDev | |||||
+ 2 // UID | + 2 // UID | ||||
+ 2 // GID | + 2 // GID | ||||
+ getLinkedFile().getBytes().length); | + getLinkedFile().getBytes().length); | ||||
@@ -135,12 +135,12 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | |||||
*/ | */ | ||||
public byte[] getLocalFileDataData() { | public byte[] getLocalFileDataData() { | ||||
// CRC will be added later | // 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); | System.arraycopy(ZipShort.getBytes(getMode()), 0, data, 0, 2); | ||||
byte[] linkArray = getLinkedFile().getBytes(); | byte[] linkArray = getLinkedFile().getBytes(); | ||||
System.arraycopy(ZipLong.getBytes(linkArray.length), | System.arraycopy(ZipLong.getBytes(linkArray.length), | ||||
0, data, 2, 4); | |||||
0, data, 2, WORD); | |||||
System.arraycopy(ZipShort.getBytes(getUserId()), | System.arraycopy(ZipShort.getBytes(getUserId()), | ||||
0, data, 6, 2); | 0, data, 6, 2); | ||||
@@ -153,9 +153,9 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | |||||
crc.update(data); | crc.update(data); | ||||
long checksum = crc.getValue(); | 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; | return result; | ||||
} | } | ||||
@@ -287,8 +287,8 @@ public class AsiExtraField implements ZipExtraField, UnixStat, Cloneable { | |||||
throws ZipException { | throws ZipException { | ||||
long givenChecksum = ZipLong.getValue(data, offset); | 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.reset(); | ||||
crc.update(tmp); | crc.update(tmp); | ||||
long realChecksum = crc.getValue(); | long realChecksum = crc.getValue(); | ||||