git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@578730 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -25,11 +25,16 @@ package org.apache.tools.ant.util; | |||
| **/ | |||
| public class Base64Converter { | |||
| private static final int BYTE = 8; | |||
| private static final int WORD = 16; | |||
| 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_1_SHIFT = 6; | |||
| private static final int POS_2_MASK = 0x0003F000; | |||
| private static final int POS_2_SHIFT = 12; | |||
| private static final int POS_3_MASK = 0x00FC0000; | |||
| private static final int POS_3_SHIFT = 18; | |||
| private static final char[] ALPHABET = { | |||
| @@ -66,44 +71,48 @@ public class Base64Converter { | |||
| int bits24; | |||
| int bits6; | |||
| // CheckStyle:MagicNumber OFF | |||
| char[] out = new char[((octetString.length - 1) / 3 + 1) * 4]; | |||
| // CheckStyle:MagicNumber ON | |||
| int outIndex = 0; | |||
| int i = 0; | |||
| // CheckStyle:MagicNumber OFF | |||
| while ((i + 3) <= octetString.length) { | |||
| // CheckStyle:MagicNumber ON | |||
| // store the octets | |||
| bits24 = (octetString[i++] & BYTE_MASK) << 16; | |||
| bits24 |= (octetString[i++] & BYTE_MASK) << 8; | |||
| bits24 = (octetString[i++] & BYTE_MASK) << WORD; | |||
| bits24 |= (octetString[i++] & BYTE_MASK) << BYTE; | |||
| bits24 |= octetString[i++]; | |||
| bits6 = (bits24 & POS_3_MASK) >> 18; | |||
| bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| bits6 = (bits24 & POS_2_MASK) >> 12; | |||
| bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| bits6 = (bits24 & POS_1_MASK) >> 6; | |||
| bits6 = (bits24 & POS_1_MASK) >> POS_1_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| 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 & POS_3_MASK) >> 18; | |||
| bits24 = (octetString[i] & BYTE_MASK) << WORD; | |||
| bits24 |= (octetString[i + 1] & BYTE_MASK) << BYTE; | |||
| bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| bits6 = (bits24 & POS_2_MASK) >> 12; | |||
| bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| bits6 = (bits24 & POS_1_MASK) >> 6; | |||
| bits6 = (bits24 & POS_1_MASK) >> POS_1_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| // padding | |||
| out[outIndex++] = '='; | |||
| } else if (octetString.length - i == 1) { | |||
| // store the octets | |||
| bits24 = (octetString[i] & BYTE_MASK) << 16; | |||
| bits6 = (bits24 & POS_3_MASK) >> 18; | |||
| bits24 = (octetString[i] & BYTE_MASK) << WORD; | |||
| bits6 = (bits24 & POS_3_MASK) >> POS_3_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| bits6 = (bits24 & POS_2_MASK) >> 12; | |||
| bits6 = (bits24 & POS_2_MASK) >> POS_2_SHIFT; | |||
| out[outIndex++] = ALPHABET[bits6]; | |||
| // padding | |||
| @@ -37,6 +37,10 @@ import java.util.TimeZone; | |||
| */ | |||
| public final class DateUtils { | |||
| private static final int ONE_SECOND = 1000; | |||
| private static final int ONE_MINUTE = 60; | |||
| private static final int ONE_HOUR = 60; | |||
| private static final int TEN = 10; | |||
| /** | |||
| * ISO8601-like pattern for date-time. It does not support timezone. | |||
| * <tt>yyyy-MM-ddTHH:mm:ss</tt> | |||
| @@ -125,9 +129,9 @@ public final class DateUtils { | |||
| * @return the formatted text in minutes/seconds. | |||
| */ | |||
| public static String formatElapsedTime(long millis) { | |||
| long seconds = millis / 1000; | |||
| long minutes = seconds / 60; | |||
| Object[] args = {new Long(minutes), new Long(seconds % 60)}; | |||
| long seconds = millis / ONE_SECOND; | |||
| long minutes = seconds / ONE_MINUTE; | |||
| Object[] args = {new Long(minutes), new Long(seconds % ONE_MINUTE)}; | |||
| return MINUTE_SECONDS.format(args); | |||
| } | |||
| @@ -179,6 +183,7 @@ public final class DateUtils { | |||
| * @since 1.2, Ant 1.5 | |||
| */ | |||
| public static int getPhaseOfMoon(Calendar cal) { | |||
| // CheckStyle:MagicNumber OFF | |||
| int dayOfTheYear = cal.get(Calendar.DAY_OF_YEAR); | |||
| int yearInMetonicCycle = ((cal.get(Calendar.YEAR) - 1900) % 19) + 1; | |||
| int epact = (11 * yearInMetonicCycle + 18) % 30; | |||
| @@ -186,6 +191,7 @@ public final class DateUtils { | |||
| epact++; | |||
| } | |||
| return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7; | |||
| // CheckStyle:MagicNumber ON | |||
| } | |||
| /** | |||
| @@ -205,13 +211,13 @@ public final class DateUtils { | |||
| cal.get(Calendar.MILLISECOND)); | |||
| StringBuffer tzMarker = new StringBuffer(offset < 0 ? "-" : "+"); | |||
| offset = Math.abs(offset); | |||
| int hours = offset / (60 * 60 * 1000); | |||
| int minutes = offset / (60 * 1000) - 60 * hours; | |||
| if (hours < 10) { | |||
| int hours = offset / (ONE_HOUR * ONE_MINUTE * ONE_SECOND); | |||
| int minutes = offset / (ONE_MINUTE * ONE_SECOND) - ONE_HOUR * hours; | |||
| if (hours < TEN) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(hours); | |||
| if (minutes < 10) { | |||
| if (minutes < TEN) { | |||
| tzMarker.append("0"); | |||
| } | |||
| tzMarker.append(minutes); | |||
| @@ -32,6 +32,7 @@ import org.apache.tools.ant.Project; | |||
| * @since Ant 1.6.2 | |||
| */ | |||
| public class LeadPipeInputStream extends PipedInputStream { | |||
| private static final int BYTE_MASK = 0xFF; | |||
| private ProjectComponent managingPc; | |||
| /** | |||
| @@ -88,7 +89,7 @@ public class LeadPipeInputStream extends PipedInputStream { | |||
| if ("write end dead".equalsIgnoreCase(eyeOhEx.getMessage())) { | |||
| if (super.in > 0 && super.out < super.buffer.length | |||
| && super.out > super.in) { | |||
| result = super.buffer[super.out++] & 0xFF; | |||
| result = super.buffer[super.out++] & BYTE_MASK; | |||
| } | |||
| } else { | |||
| log("error at LeadPipeInputStream.read(): " | |||
| @@ -29,8 +29,9 @@ import org.apache.tools.ant.ProjectComponent; | |||
| */ | |||
| public class LineTokenizer extends ProjectComponent | |||
| implements Tokenizer { | |||
| private static final int NOT_A_CHAR = -2; | |||
| private String lineEnd = ""; | |||
| private int pushed = -2; | |||
| private int pushed = NOT_A_CHAR; | |||
| private boolean includeDelims = false; | |||
| /** | |||
| @@ -54,9 +55,9 @@ public class LineTokenizer extends ProjectComponent | |||
| */ | |||
| public String getToken(Reader in) throws IOException { | |||
| int ch = -1; | |||
| if (pushed != -2) { | |||
| if (pushed != NOT_A_CHAR) { | |||
| ch = pushed; | |||
| pushed = -2; | |||
| pushed = NOT_A_CHAR; | |||
| } else { | |||
| ch = in.read(); | |||
| } | |||
| @@ -27,6 +27,7 @@ import java.io.Reader; | |||
| * | |||
| */ | |||
| public class ReaderInputStream extends InputStream { | |||
| private static final int BYTE_MASK = 0xFF; | |||
| /** Source Reader */ | |||
| private Reader in; | |||
| @@ -90,7 +91,7 @@ public class ReaderInputStream extends InputStream { | |||
| result = buf[0]; | |||
| } | |||
| } | |||
| return result & 0xFF; | |||
| return result & BYTE_MASK; | |||
| } | |||
| /** | |||
| @@ -31,8 +31,9 @@ import org.apache.tools.ant.ProjectComponent; | |||
| * @since Ant 1.7 | |||
| */ | |||
| public class StringTokenizer extends ProjectComponent implements Tokenizer { | |||
| private static final int NOT_A_CHAR = -2; | |||
| private String intraString = ""; | |||
| private int pushed = -2; | |||
| private int pushed = NOT_A_CHAR; | |||
| private char[] delims = null; | |||
| private boolean delimsAreTokens = false; | |||
| private boolean suppressDelims = false; | |||
| @@ -83,9 +84,9 @@ public class StringTokenizer extends ProjectComponent implements Tokenizer { | |||
| */ | |||
| public String getToken(Reader in) throws IOException { | |||
| int ch = -1; | |||
| if (pushed != -2) { | |||
| if (pushed != NOT_A_CHAR) { | |||
| ch = pushed; | |||
| pushed = -2; | |||
| pushed = NOT_A_CHAR; | |||
| } else { | |||
| ch = in.read(); | |||
| } | |||
| @@ -126,10 +126,12 @@ public class UUEncoder { | |||
| } | |||
| } | |||
| // CheckStyle:MagicNumber OFF | |||
| byte d1 = (byte) (((a >>> 2) & 0x3F) + ' '); | |||
| byte d2 = (byte) ((((a << 4) & 0x30) | ((b >>> 4) & 0x0F)) + ' '); | |||
| byte d3 = (byte) ((((b << 2) & 0x3C) | ((c >>> 6) & 0x3)) + ' '); | |||
| byte d4 = (byte) ((c & 0x3F) + ' '); | |||
| // CheckStyle:MagicNumber ON | |||
| out.write(d1); | |||
| out.write(d2); | |||