You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by hi...@apache.org on 2010/09/21 21:46:00 UTC
svn commit: r999573 [2/4] - in /harmony/enhanced/java/branches/mrh: ./
classlib/ classlib/depends/build/ classlib/depends/files/
classlib/depends/jars/ classlib/depends/manifests/icu4j_4.2.1/META-INF/
classlib/depends/manifests/icu4j_4.4.1.1/ classlib/...
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/CharsetProviderImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/CharsetProviderImpl.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/CharsetProviderImpl.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/CharsetProviderImpl.java Tue Sep 21 19:45:57 2010
@@ -20,6 +20,7 @@ package org.apache.harmony.niochar;
import java.lang.reflect.Constructor;
import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.spi.CharsetProvider;
import java.security.AccessController;
import java.security.PrivilegedAction;
@@ -100,6 +101,40 @@ public class CharsetProviderImpl extends
*/
protected String packageName;
+ /*
+ * Utility to convert valid charset names to upper case
+ */
+ private static String toUpperCase(String name) {
+ int length = name.length();
+ char[] output = new char[length];
+ for (int i = 0; i < length; i++) {
+ char ch = name.charAt(i);
+ if (passthru(ch)) {
+ output[i] = ch;
+ } else {
+ if ((ch >= '\u0061') && (ch <= '\u007A')) {
+ // Lowercase 'a' to 'z'
+ output[i] = (char) (ch - ('a' - 'A'));
+ } else {
+ throw new IllegalCharsetNameException(name);
+ }
+ }
+ }
+ return new String(output);
+ }
+
+ /*
+ * Answers true if the character is already considered uppercase, false otherwise.
+ */
+ private static boolean passthru(char c) {
+ return ((c >= '\u0041') && (c <= '\u005A')) || // Uppercase letters 'A' to 'Z'
+ ((c >= '\u0030') && (c <= '\u0039')) || // Digits '0' to '9'
+ (c == '\u002D') || // Dash '-'
+ (c == '\u002E') || // Period '.'
+ (c == '\u003A') || // Colon ':'
+ (c == '\u005F'); // Underscore '_'
+ }
+
/**
* Default constructor for the built-in charset provider implementation.
*/
@@ -110,7 +145,7 @@ public class CharsetProviderImpl extends
for (int i = 0; i < charsets.length; i++) {
String aliases[] = (String[]) charsets[i][CHARSET_ALIASES];
for (int a = 0; a < aliases.length; a++) {
- cache.put(aliases[a].toUpperCase(), charsets[i]);
+ cache.put(toUpperCase(aliases[a]), charsets[i]);
}
}
}
@@ -142,7 +177,7 @@ public class CharsetProviderImpl extends
*/
@Override
public Charset charsetForName(String charsetName) {
- Object arr[] = cache.get(charsetName.toUpperCase());
+ Object arr[] = cache.get(toUpperCase(charsetName));
if (arr == null) {
return null;
}
@@ -330,8 +365,8 @@ public class CharsetProviderImpl extends
"X-UTF-16BE",
"UTF_16BE" } },
- { "IBM866", null, new String[] { "cp866",
- "IBM866",
+ { "IBM866", null, new String[] { "IBM866",
+ "cp866",
"866",
"csIBM866" } },
@@ -380,8 +415,8 @@ public class CharsetProviderImpl extends
"cp775",
"csPC775Baltic" } },
- { "additional.IBM850", null, new String[] { "cp850",
- "IBM850",
+ { "additional.IBM850", null, new String[] { "IBM850",
+ "cp850",
"850",
"csPC850Multilingual" } },
@@ -395,46 +430,46 @@ public class CharsetProviderImpl extends
"855",
"csIBM855" } },
- { "additional.IBM857", null, new String[] { "cp857",
- "IBM857",
+ { "additional.IBM857", null, new String[] { "IBM857",
+ "cp857",
"857",
"csIBM857" } },
- { "additional.IBM860", null, new String[] { "cp860",
- "IBM860",
+ { "additional.IBM860", null, new String[] { "IBM860",
+ "cp860",
"860",
"csIBM860" } },
- { "additional.IBM861", null, new String[] { "cp861",
- "IBM861",
+ { "additional.IBM861", null, new String[] { "IBM861",
+ "cp861",
"861",
"cp-is",
"csIBM861" } },
- { "additional.IBM862", null, new String[] { "cp862",
- "IBM862",
+ { "additional.IBM862", null, new String[] { "IBM862",
+ "cp862",
"862",
"csPC862LatinHebrew" } },
- { "additional.IBM863", null, new String[] { "cp863",
- "IBM863",
+ { "additional.IBM863", null, new String[] { "IBM863",
+ "cp863",
"863",
"csIBM863" } },
- { "additional.IBM865", null, new String[] { "cp865",
- "IBM865",
+ { "additional.IBM865", null, new String[] { "IBM865",
+ "cp865",
"865",
"csIBM865" } },
- { "additional.IBM869", null, new String[] { "cp869",
- "IBM869",
+ { "additional.IBM869", null, new String[] { "IBM869",
+ "cp869",
"869",
"cp-gr",
"csIBM869" } },
- { "additional.IBM00858", null, new String[] { "cp858",
- "IBM00858",
+ { "additional.IBM00858", null, new String[] { "IBM00858",
+ "cp858",
"CCSID00858",
"CP00858" } },
@@ -545,12 +580,12 @@ public class CharsetProviderImpl extends
"ebcdic-cp-ar1",
"csIBM420" } },
- { "additional.IBM864", null, new String[] { "cp864",
- "IBM864",
+ { "additional.IBM864", null, new String[] { "IBM864",
+ "cp864",
"csIBM864" } },
- { "additional.IBM868", null, new String[] { "cp868",
- "IBM868",
+ { "additional.IBM868", null, new String[] { "IBM868",
+ "cp868",
"cp-ar",
"csIBM868" } },
@@ -585,66 +620,66 @@ public class CharsetProviderImpl extends
{ "additional.IBM_Thai", null, new String[] { "IBM-Thai",
"cp838" } },
- { "additional.x_IBM737", null, new String[] { "x-ibm-737_P100-1997",
- "x-IBM737",
+ { "additional.x_IBM737", null, new String[] { "x-IBM737",
+ "x-ibm-737_P100-1997",
"cp737" } },
- { "additional.x_IBM856", null, new String[] { "cp856",
- "x-IBM856"} },
+ { "additional.x_IBM856", null, new String[] { "x-IBM856",
+ "cp856"} },
{ "additional.x_IBM874", null, new String[] { "TIS-620",
"x-IBM874",
"cp874"} },
- { "additional.x_IBM875", null, new String[] { "x-ibm-875_P100-1995",
- "x-IBM875",
+ { "additional.x_IBM875", null, new String[] { "x-IBM875",
+ "x-ibm-875_P100-1995",
"cp875"} },
- { "additional.x_IBM922", null, new String[] { "cp922",
- "x-IBM922"} },
+ { "additional.x_IBM922", null, new String[] {"x-IBM922",
+ "cp922"} },
- { "additional.x_IBM1006", null, new String[] { "x-ibm-1006_P100-1995",
- "x-IBM1006",
+ { "additional.x_IBM1006", null, new String[] { "x-IBM1006",
+ "x-ibm-1006_P100-1995",
"cp1006"} },
- { "additional.x_IBM1025", null, new String[] { "x-ibm-1025_P100-1995",
- "x-IBM1025",
+ { "additional.x_IBM1025", null, new String[] { "x-IBM1025",
+ "x-ibm-1025_P100-1995",
"cp1025"} },
- { "additional.x_IBM1112", null, new String[] { "x-ibm-1112_P100-1995",
- "x-IBM1112",
+ { "additional.x_IBM1112", null, new String[] { "x-IBM1112",
+ "x-ibm-1112_P100-1995",
"cp1112"} },
- { "additional.x_IBM1122", null, new String[] { "x-ibm-1122_P100-1999",
- "x-IBM1122",
+ { "additional.x_IBM1122", null, new String[] { "x-IBM1122",
+ "x-ibm-1122_P100-1999",
"cp1122"} },
- { "additional.x_IBM1123", null, new String[] { "x-ibm-1123_P100-1995",
- "x-IBM1123",
+ { "additional.x_IBM1123", null, new String[] { "x-IBM1123",
+ "x-ibm-1123_P100-1995",
"cp1123"} },
- { "additional.x_IBM1124", null, new String[] { "x-ibm-1124_P100-1996",
- "x-IBM1124",
+ { "additional.x_IBM1124", null, new String[] { "x-IBM1124",
+ "x-ibm-1124_P100-1996",
"cp1124"} },
- { "additional.x_IBM1097", null, new String[] { "x-ibm-1097_P100-1995",
- "x-IBM1097",
+ { "additional.x_IBM1097", null, new String[] { "x-IBM1097",
+ "x-ibm-1097_P100-1995",
"cp1097"} },
- { "additional.x_IBM1098", null, new String[] { "x-ibm-1098_P100-1995",
- "x-IBM1098",
+ { "additional.x_IBM1098", null, new String[] { "x-IBM1098",
+ "x-ibm-1098_P100-1995",
"cp1098"} },
- { "additional.x_MacCyrillic", null, new String[] { "x-mac-cyrillic",
- "x-MacCyrillic",
+ { "additional.x_MacCyrillic", null, new String[] { "x-MacCyrillic",
+ "x-mac-cyrillic",
"MacCyrillic"} },
- { "additional.x_MacGreek", null, new String[] { "x-mac-greek",
- "x-MacGreek",
+ { "additional.x_MacGreek", null, new String[] { "x-MacGreek",
+ "x-mac-greek",
"MacGreek"} },
- { "additional.x_MacTurkish", null, new String[] { "x-mac-turkish",
- "x-MacTurkish",
+ { "additional.x_MacTurkish", null, new String[] { "x-MacTurkish",
+ "x-mac-turkish",
"MacTurkish"} },
{ "additional.windows_31j", null, new String[] { "Shift_JIS",
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/main/java/org/apache/harmony/niochar/charset/UTF_8.java Tue Sep 21 19:45:57 2010
@@ -26,44 +26,6 @@ import java.nio.charset.CoderResult;
public class UTF_8 extends Charset {
- // The next table contains information about UTF-8 charset and
- // correspondence of 1st byte to the length of sequence
- // For information please visit http://www.ietf.org/rfc/rfc3629.txt
- //
- // Please note, o means 0, actually.
- // -------------------------------------------------------------------
- // 0 1 2 3 Value
- // -------------------------------------------------------------------
- // oxxxxxxx 00000000 00000000 0xxxxxxx
- // 11oyyyyy 1oxxxxxx 00000000 00000yyy yyxxxxxx
- // 111ozzzz 1oyyyyyy 1oxxxxxx 00000000 zzzzyyyy yyxxxxxx
- // 1111ouuu 1ouuzzzz 1oyyyyyy 1oxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
-
- private static final int remainingBytes[] = {
- // 1owwwwww
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- // 11oyyyyy
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- // 111ozzzz
- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
- // 1111ouuu
- 3, 3, 3, 3, 3, 3, 3, 3,
- // > 11110111
- -1, -1, -1, -1, -1, -1, -1, -1 };
-
- private static final int remainingNumbers[] = {
- 0, // 0 1 2 3
- 4224, // (01o00000b << 6)+(1o000000b)
- 401536, // (011o0000b << 12)+(1o000000b << 6)+(1o000000b)
- 29892736 // (0111o000b << 18)+(1o000000b << 12)+(1o000000b << 6)+(1o000000b)
- };
-
- private static final int lowerEncodingLimit[] = { -1, 0x80, 0x800, 0x10000 };
-
public UTF_8(String canonicalName, String[] aliases) {
super(canonicalName, aliases);
}
@@ -96,188 +58,357 @@ public class UTF_8 extends Charset {
|| cs.name().equalsIgnoreCase("UTF-16BE");
}
+ @Override
public CharsetDecoder newDecoder() {
return new Decoder(this);
}
+ @Override
public CharsetEncoder newEncoder() {
return new Encoder(this);
}
- private final class Decoder extends CharsetDecoder {
+ private static final class Decoder extends CharsetDecoder {
+
+ // The next table contains information about UTF-8 charset and
+ // correspondence of 1st byte to the length of sequence
+ // For information please visit http://www.ietf.org/rfc/rfc3629.txt
+ //
+ // Please note, o means 0, actually.
+ // -------------------------------------------------------------------
+ // 0 1 2 3 Value
+ // -------------------------------------------------------------------
+ // oxxxxxxx 00000000 00000000 0xxxxxxx
+ // 11oyyyyy 1oxxxxxx 00000000 00000yyy yyxxxxxx
+ // 111ozzzz 1oyyyyyy 1oxxxxxx 00000000 zzzzyyyy yyxxxxxx
+ // 1111ouuu 1ouuzzzz 1oyyyyyy 1oxxxxxx 000uuuuu zzzzyyyy yyxxxxxx
+
+ private static final int remainingBytes[] = {
+ // 1owwwwww
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ // 11oyyyyy
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ // 111ozzzz
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ // 1111ouuu
+ 3, 3, 3, 3, 3, 3, 3, 3,
+ // > 11110111
+ -1, -1, -1, -1, -1, -1, -1, -1 };
+
+ private static final int remainingNumbers[] = {
+ 0, // 0 1 2 3
+ 4224, // (01o00000b << 6)+(1o000000b)
+ 401536, // (011o0000b << 12)+(1o000000b << 6)+(1o000000b)
+ 29892736 // (0111o000b << 18)+(1o000000b << 12)+(1o000000b << 6)+(1o000000b)
+ };
- private Decoder(Charset cs) {
+ private static final int lowerEncodingLimit[] = { -1, 0x80, 0x800, 0x10000 };
+
+ Decoder(Charset cs) {
super(cs, 1.0f, 1.0f);
}
+ @Override
protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) {
+ if (in.hasArray() && out.hasArray()) {
+ return decodeHasArray(in, out);
+ }
+ return decodeNotHasArray(in, out);
+ }
+
+ private CoderResult decodeNotHasArray(ByteBuffer in, CharBuffer out) {
int outRemaining = out.remaining();
int pos = in.position();
int limit = in.limit();
- if (in.hasArray() && out.hasArray()) {
- final byte[] bArr = in.array();
- final char[] cArr = out.array();
- final int inIndexLimit = limit + in.arrayOffset();
-
- int inIndex = pos + in.arrayOffset();
- int outIndex = out.position() + out.arrayOffset();
-
- // if someone would change the limit in process,
- // he would face consequences
- for (; inIndex < inIndexLimit && outRemaining > 0; inIndex++) {
- int jchar = bArr[inIndex];
+ try {
+ while (pos < limit) {
+ if (outRemaining == 0) {
+ return CoderResult.OVERFLOW;
+ }
+
+ int jchar = in.get();
if (jchar < 0) {
jchar = jchar & 0x7F;
int tail = remainingBytes[jchar];
-
if (tail == -1) {
- in.position(inIndex - in.arrayOffset());
- out.position(outIndex - out.arrayOffset());
return CoderResult.malformedForLength(1);
}
- if (inIndexLimit - inIndex < 1 + tail) {
- break;
+ if (limit - pos < 1 + tail) {
+ return CoderResult.UNDERFLOW;
}
+ int nextByte;
for (int i = 0; i < tail; i++) {
- int nextByte = bArr[inIndex + i + 1] & 0xFF;
+ nextByte = in.get() & 0xFF;
if ((nextByte & 0xC0) != 0x80) {
- in.position(inIndex - in.arrayOffset());
- out.position(outIndex - out.arrayOffset());
- return CoderResult.malformedForLength(1 + i);
+ return CoderResult
+ .malformedForLength(1 + i);
}
jchar = (jchar << 6) + nextByte;
}
jchar -= remainingNumbers[tail];
if (jchar < lowerEncodingLimit[tail]) {
- // Should have been encoded in fewer octets
- in.position(inIndex - in.arrayOffset());
- out.position(outIndex - out.arrayOffset());
+ // Should have been encoded in a fewer octets
return CoderResult.malformedForLength(1);
}
- inIndex += tail;
+ pos += tail;
}
- cArr[outIndex++] = (char) jchar;
- outRemaining--;
+ if (jchar <= 0xffff) {
+ out.put((char) jchar);
+ outRemaining--;
+ } else {
+ if (outRemaining < 2) {
+ return CoderResult.OVERFLOW;
+ }
+ out.put((char) ((jchar >> 0xA) + 0xD7C0));
+ out.put((char) ((jchar & 0x3FF) + 0xDC00));
+ outRemaining -= 2;
+ }
+ pos++;
}
- in.position(inIndex - in.arrayOffset());
- out.position(outIndex - out.arrayOffset());
- return (outRemaining == 0 && inIndex < inIndexLimit) ? CoderResult.OVERFLOW
- : CoderResult.UNDERFLOW;
- } else {
- try {
- while (pos < limit) {
- if (outRemaining == 0) {
- return CoderResult.OVERFLOW;
- }
+ return CoderResult.UNDERFLOW;
+ } finally {
+ in.position(pos);
+ }
+ }
- int jchar = in.get();
- if (jchar < 0) {
- jchar = jchar & 0x7F;
- int tail = remainingBytes[jchar];
- if (tail == -1) {
- return CoderResult.malformedForLength(1);
- }
- if (limit - pos < 1 + tail) {
- return CoderResult.UNDERFLOW;
- }
+ private CoderResult decodeHasArray(ByteBuffer in, CharBuffer out) {
+ int outRemaining = out.remaining();
+ int pos = in.position();
+ int limit = in.limit();
+ final byte[] bArr = in.array();
+ final char[] cArr = out.array();
+ final int inIndexLimit = limit + in.arrayOffset();
+
+ int inIndex = pos + in.arrayOffset();
+ int outIndex = out.position() + out.arrayOffset();
+
+ // if someone would change the limit in process,
+ // he would face consequences
+ for (; inIndex < inIndexLimit && outRemaining > 0; inIndex++) {
+ int jchar = bArr[inIndex];
+ if (jchar < 0) {
+ jchar = jchar & 0x7F;
+ int tail = remainingBytes[jchar];
+
+ if (tail == -1) {
+ in.position(inIndex - in.arrayOffset());
+ out.position(outIndex - out.arrayOffset());
+ return CoderResult.malformedForLength(1);
+ }
+ if (inIndexLimit - inIndex < 1 + tail) {
+ break;
+ }
- int nextByte;
- for (int i = 0; i < tail; i++) {
- nextByte = in.get() & 0xFF;
- if ((nextByte & 0xC0) != 0x80) {
- return CoderResult
- .malformedForLength(1 + i);
- }
- jchar = (jchar << 6) + nextByte;
- }
- jchar -= remainingNumbers[tail];
- if (jchar < lowerEncodingLimit[tail]) {
- // Should have been encoded in a fewer octets
- return CoderResult.malformedForLength(1);
- }
- pos += tail;
+ for (int i = 0; i < tail; i++) {
+ int nextByte = bArr[inIndex + i + 1] & 0xFF;
+ if ((nextByte & 0xC0) != 0x80) {
+ in.position(inIndex - in.arrayOffset());
+ out.position(outIndex - out.arrayOffset());
+ return CoderResult.malformedForLength(1 + i);
}
- pos++;
- out.put((char) jchar);
- outRemaining--;
+ jchar = (jchar << 6) + nextByte;
}
- return CoderResult.UNDERFLOW;
- } finally {
- in.position(pos);
+ jchar -= remainingNumbers[tail];
+ if (jchar < lowerEncodingLimit[tail]) {
+ // Should have been encoded in fewer octets
+ in.position(inIndex - in.arrayOffset());
+ out.position(outIndex - out.arrayOffset());
+ return CoderResult.malformedForLength(1);
+ }
+ inIndex += tail;
+ }
+ if (jchar <= 0xffff) {
+ cArr[outIndex++] = (char) jchar;
+ outRemaining--;
+ } else {
+ if (outRemaining < 2) {
+ return CoderResult.OVERFLOW;
+ }
+ cArr[outIndex++] = (char) ((jchar >> 0xA) + 0xD7C0);
+ cArr[outIndex++] = (char) ((jchar & 0x3FF) + 0xDC00);
+ outRemaining -= 2;
}
}
+ in.position(inIndex - in.arrayOffset());
+ out.position(outIndex - out.arrayOffset());
+ return (outRemaining == 0 && inIndex < inIndexLimit) ? CoderResult.OVERFLOW
+ : CoderResult.UNDERFLOW;
}
+
}
- private final class Encoder extends CharsetEncoder {
+ private static final class Encoder extends CharsetEncoder {
- private Encoder(Charset cs) {
+ Encoder(Charset cs) {
super(cs, 1.1f, 4.0f);
}
+ @Override
protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out) {
+ if (in.hasArray() && out.hasArray()) {
+ return encodeHasArray(in, out);
+ }
+ return encodeNotHasArray(in, out);
+ }
+
+ private CoderResult encodeHasArray(CharBuffer in, ByteBuffer out) {
int outRemaining = out.remaining();
int pos = in.position();
int limit = in.limit();
- if (in.hasArray() && out.hasArray()) {
- byte[] bArr;
- char[] cArr;
- int x = pos;
- bArr = out.array();
- cArr = in.array();
- int outPos = out.position();
- int rem = in.remaining();
- for (x = pos; x < pos + rem; x++) {
- int jchar = (cArr[x] & 0xFFFF);
+ byte[] bArr;
+ char[] cArr;
+ int x = pos;
+ bArr = out.array();
+ cArr = in.array();
+ int outPos = out.position();
+ int rem = in.remaining();
+ for (x = pos; x < pos + rem; x++) {
+ int jchar = (cArr[x] & 0xFFFF);
+
+ if (jchar <= 0x7F) {
+ if (outRemaining < 1) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.OVERFLOW;
+ }
+ bArr[outPos++] = (byte) (jchar & 0xFF);
+ outRemaining--;
+ } else if (jchar <= 0x7FF) {
+
+ if (outRemaining < 2) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.OVERFLOW;
+ }
+ bArr[outPos++] = (byte) (0xC0 + ((jchar >> 6) & 0x1F));
+ bArr[outPos++] = (byte) (0x80 + (jchar & 0x3F));
+ outRemaining -= 2;
+
+ } else if (jchar >= 0xD800 && jchar <= 0xDFFF) {
+
+ // in has to have one byte more.
+ if (limit <= x + 1) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.UNDERFLOW;
+ }
+
+ if (outRemaining < 4) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.OVERFLOW;
+ }
+
+ // The surrogate pair starts with a low-surrogate.
+ if (jchar >= 0xDC00) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.malformedForLength(1);
+ }
+
+ int jchar2 = cArr[x + 1] & 0xFFFF;
+
+ // The surrogate pair ends with a high-surrogate.
+ if (jchar2 < 0xDC00) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.malformedForLength(1);
+ }
+
+ // Note, the Unicode scalar value n is defined
+ // as follows:
+ // n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
+ // Where jchar is a high-surrogate,
+ // jchar2 is a low-surrogate.
+ int n = (jchar << 10) + jchar2 + 0xFCA02400;
+
+ bArr[outPos++] = (byte) (0xF0 + ((n >> 18) & 0x07));
+ bArr[outPos++] = (byte) (0x80 + ((n >> 12) & 0x3F));
+ bArr[outPos++] = (byte) (0x80 + ((n >> 6) & 0x3F));
+ bArr[outPos++] = (byte) (0x80 + (n & 0x3F));
+ outRemaining -= 4;
+ x++;
+
+ } else {
+
+ if (outRemaining < 3) {
+ in.position(x);
+ out.position(outPos);
+ return CoderResult.OVERFLOW;
+ }
+ bArr[outPos++] = (byte) (0xE0 + ((jchar >> 12) & 0x0F));
+ bArr[outPos++] = (byte) (0x80 + ((jchar >> 6) & 0x3F));
+ bArr[outPos++] = (byte) (0x80 + (jchar & 0x3F));
+ outRemaining -= 3;
+ }
+ if (outRemaining == 0) {
+ in.position(x + 1);
+ out.position(outPos);
+ return CoderResult.OVERFLOW;
+ }
+
+ }
+ if (rem != 0) {
+ in.position(x);
+ out.position(outPos);
+ }
+ return CoderResult.UNDERFLOW;
+ }
+
+ private CoderResult encodeNotHasArray(CharBuffer in, ByteBuffer out) {
+ int outRemaining = out.remaining();
+ int pos = in.position();
+ int limit = in.limit();
+ try {
+ while (pos < limit) {
+ if (outRemaining == 0) {
+ return CoderResult.OVERFLOW;
+ }
+
+ int jchar = (in.get() & 0xFFFF);
if (jchar <= 0x7F) {
+
if (outRemaining < 1) {
- in.position(x);
- out.position(outPos);
return CoderResult.OVERFLOW;
}
- bArr[outPos++] = (byte) (jchar & 0xFF);
+ out.put((byte) (jchar & 0xFF));
outRemaining--;
+
} else if (jchar <= 0x7FF) {
if (outRemaining < 2) {
- in.position(x);
- out.position(outPos);
return CoderResult.OVERFLOW;
}
- bArr[outPos++] = (byte) (0xC0 + ((jchar >> 6) & 0x1F));
- bArr[outPos++] = (byte) (0x80 + (jchar & 0x3F));
+ out.put((byte) (0xC0 + ((jchar >> 6) & 0x1F)));
+ out.put((byte) (0x80 + (jchar & 0x3F)));
outRemaining -= 2;
} else if (jchar >= 0xD800 && jchar <= 0xDFFF) {
// in has to have one byte more.
- if (limit <= x + 1) {
- in.position(x);
- out.position(outPos);
+ if (limit <= pos + 1) {
return CoderResult.UNDERFLOW;
}
if (outRemaining < 4) {
- in.position(x);
- out.position(outPos);
return CoderResult.OVERFLOW;
}
// The surrogate pair starts with a low-surrogate.
if (jchar >= 0xDC00) {
- in.position(x);
- out.position(outPos);
return CoderResult.malformedForLength(1);
}
- int jchar2 = cArr[x + 1] & 0xFFFF;
+ int jchar2 = (in.get() & 0xFFFF);
// The surrogate pair ends with a high-surrogate.
if (jchar2 < 0xDC00) {
- in.position(x);
- out.position(outPos);
return CoderResult.malformedForLength(1);
}
@@ -288,116 +419,28 @@ public class UTF_8 extends Charset {
// jchar2 is a low-surrogate.
int n = (jchar << 10) + jchar2 + 0xFCA02400;
- bArr[outPos++] = (byte) (0xF0 + ((n >> 18) & 0x07));
- bArr[outPos++] = (byte) (0x80 + ((n >> 12) & 0x3F));
- bArr[outPos++] = (byte) (0x80 + ((n >> 6) & 0x3F));
- bArr[outPos++] = (byte) (0x80 + (n & 0x3F));
+ out.put((byte) (0xF0 + ((n >> 18) & 0x07)));
+ out.put((byte) (0x80 + ((n >> 12) & 0x3F)));
+ out.put((byte) (0x80 + ((n >> 6) & 0x3F)));
+ out.put((byte) (0x80 + (n & 0x3F)));
outRemaining -= 4;
- x++;
+ pos++;
} else {
if (outRemaining < 3) {
- in.position(x);
- out.position(outPos);
return CoderResult.OVERFLOW;
}
- bArr[outPos++] = (byte) (0xE0 + ((jchar >> 12) & 0x0F));
- bArr[outPos++] = (byte) (0x80 + ((jchar >> 6) & 0x3F));
- bArr[outPos++] = (byte) (0x80 + (jchar & 0x3F));
+ out.put((byte) (0xE0 + ((jchar >> 12) & 0x0F)));
+ out.put((byte) (0x80 + ((jchar >> 6) & 0x3F)));
+ out.put((byte) (0x80 + (jchar & 0x3F)));
outRemaining -= 3;
}
- if (outRemaining == 0) {
- in.position(x + 1);
- out.position(outPos);
- return CoderResult.OVERFLOW;
- }
-
- }
- if (rem != 0) {
- in.position(x);
- out.position(outPos);
- }
- } else {
- try {
- while (pos < limit) {
- if (outRemaining == 0) {
- return CoderResult.OVERFLOW;
- }
-
- int jchar = (in.get() & 0xFFFF);
-
- if (jchar <= 0x7F) {
-
- if (outRemaining < 1) {
- return CoderResult.OVERFLOW;
- }
- out.put((byte) (jchar & 0xFF));
- outRemaining--;
-
- } else if (jchar <= 0x7FF) {
-
- if (outRemaining < 2) {
- return CoderResult.OVERFLOW;
- }
- out.put((byte) (0xC0 + ((jchar >> 6) & 0x1F)));
- out.put((byte) (0x80 + (jchar & 0x3F)));
- outRemaining -= 2;
-
- } else if (jchar >= 0xD800 && jchar <= 0xDFFF) {
-
- // in has to have one byte more.
- if (limit <= pos + 1) {
- return CoderResult.UNDERFLOW;
- }
-
- if (outRemaining < 4) {
- return CoderResult.OVERFLOW;
- }
-
- // The surrogate pair starts with a low-surrogate.
- if (jchar >= 0xDC00) {
- return CoderResult.malformedForLength(1);
- }
-
- int jchar2 = (in.get() & 0xFFFF);
-
- // The surrogate pair ends with a high-surrogate.
- if (jchar2 < 0xDC00) {
- return CoderResult.malformedForLength(1);
- }
-
- // Note, the Unicode scalar value n is defined
- // as follows:
- // n = (jchar-0xD800)*0x400+(jchar2-0xDC00)+0x10000
- // Where jchar is a high-surrogate,
- // jchar2 is a low-surrogate.
- int n = (jchar << 10) + jchar2 + 0xFCA02400;
-
- out.put((byte) (0xF0 + ((n >> 18) & 0x07)));
- out.put((byte) (0x80 + ((n >> 12) & 0x3F)));
- out.put((byte) (0x80 + ((n >> 6) & 0x3F)));
- out.put((byte) (0x80 + (n & 0x3F)));
- outRemaining -= 4;
- pos++;
-
- } else {
-
- if (outRemaining < 3) {
- return CoderResult.OVERFLOW;
- }
- out.put((byte) (0xE0 + ((jchar >> 12) & 0x0F)));
- out.put((byte) (0x80 + ((jchar >> 6) & 0x3F)));
- out.put((byte) (0x80 + (jchar & 0x3F)));
- outRemaining -= 3;
- }
- pos++;
- }
- } finally {
- in.position(pos);
+ pos++;
}
+ } finally {
+ in.position(pos);
}
-
return CoderResult.UNDERFLOW;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/nio_char/src/test/java/tests/api/java/nio/charset/UTF8CharsetTest.java Tue Sep 21 19:45:57 2010
@@ -16,6 +16,8 @@
package tests.api.java.nio.charset;
+import java.io.UnsupportedEncodingException;
+
/**
* Test UTF-8 charset.
*/
@@ -50,4 +52,11 @@ public class UTF8CharsetTest extends Abs
byte[] output = new byte[] { 97, 98, -27, -76, -108, -26, -107, -113 };
internalTestEncode(input, output);
}
+
+ public void test_surrogate() throws UnsupportedEncodingException {
+ // U+1D11E: MUSICAL SYMBOL G CLEF
+ String s = new StringBuilder().appendCodePoint(0x1D11E).toString();
+ byte utf8[] = s.getBytes("UTF-8");
+ assertEquals(s, new String(utf8, 0, utf8.length, "UTF-8"));
+ }
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java Tue Sep 21 19:45:57 2010
@@ -146,7 +146,7 @@ public class Archive {
List classes = new ArrayList();
List files = new ArrayList();
long segmentLimit = options.getSegmentLimit();
-
+
int size = packingFileList.size();
PackingFile packingFile;
for (int index = 0; index < size; index++) {
@@ -221,9 +221,9 @@ public class Archive {
static class SegmentUnit {
- private List classList;
+ private final List classList;
- private List fileList;
+ private final List fileList;
private int byteAmount = 0;
@@ -323,6 +323,10 @@ public class Archive {
public boolean isDirectory(){
return isDirectory;
}
+
+ public String toString() {
+ return name;
+ }
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Tue Sep 21 19:45:57 2010
@@ -331,26 +331,6 @@ public abstract class BandSet {
}
}
- /**
- * Returns true if the name of the source file can be predicted from the
- * class name
- *
- * @param className
- * the class name
- * @param sourceFileName
- * the source file name
- */
- public boolean isPredictableSourceFileName(String className, String sourceFileName) {
- if (className.indexOf('.') != -1) {
- className = className.substring(className.lastIndexOf('.') + 1);
- }
- if (className.indexOf('$') != -1) {
- className = className.substring(0, className.indexOf('$'));
- }
- className += ".java";
- return className.equals(sourceFileName);
- }
-
// This could be useful if further enhancements are done but is not currently used
//
// private void encodeWithRunCodec(String name, int[] band, int index,
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPMethodOrField.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPMethodOrField.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPMethodOrField.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPMethodOrField.java Tue Sep 21 19:45:57 2010
@@ -31,18 +31,6 @@ public class CPMethodOrField extends Con
this.nameAndType = nameAndType;
}
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof CPMethodOrField)) {
- return false;
- }
- return ((CPMethodOrField) obj).className.equals(className)
- && ((CPMethodOrField) obj).nameAndType.equals(nameAndType);
- }
-
- public int hashCode() {
- return className.hashCode() + nameAndType.hashCode();
- }
-
public String toString() {
return className + ": " + nameAndType;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPNameAndType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPNameAndType.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPNameAndType.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CPNameAndType.java Tue Sep 21 19:45:57 2010
@@ -29,18 +29,6 @@ public class CPNameAndType extends Const
this.signature = signature;
}
- public boolean equals(Object obj) {
- if (obj == null || !(obj instanceof CPNameAndType)) {
- return false;
- }
- return ((CPNameAndType) obj).name.equals(name)
- && ((CPNameAndType) obj).signature.equals(signature);
- }
-
- public int hashCode() {
- return name.hashCode() + signature.hashCode();
- }
-
public String toString() {
return name + ":" + signature;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Tue Sep 21 19:45:57 2010
@@ -119,6 +119,8 @@ public class ClassBands extends BandSet
private final List tempFieldDesc = new ArrayList();
private final List tempMethodFlags = new ArrayList();
private final List tempMethodDesc = new ArrayList();
+ private TempParamAnnotation tempMethodRVPA;
+ private TempParamAnnotation tempMethodRIPA;
private boolean anySyntheticClasses = false;
private boolean anySyntheticFields = false;
@@ -153,6 +155,10 @@ public class ClassBands extends BandSet
field_flags = new long[numClasses][];
method_descr = new CPNameAndType[numClasses][];
method_flags = new long[numClasses][];
+ for (int i = 0; i < numClasses; i++) {
+ field_flags[i] = new long[0];
+ method_flags[i] = new long[0];
+ }
// minor_versions = new int[numClasses];
major_versions = new int[numClasses];
class_flags = new long[numClasses];
@@ -520,7 +526,7 @@ public class ClassBands extends BandSet
int totalFields = sum(class_field_count);
int[] fieldDescr = new int[totalFields];
k = 0;
- for (int i = 0; i < field_descr.length; i++) {
+ for (int i = 0; i < index; i++) {
for (int j = 0; j < field_descr[i].length; j++) {
CPNameAndType descr = field_descr[i][j];
fieldDescr[k] = descr.getIndex();
@@ -538,7 +544,7 @@ public class ClassBands extends BandSet
int totalMethods = sum(class_method_count);
int[] methodDescr = new int[totalMethods];
k = 0;
- for (int i = 0; i < method_descr.length; i++) {
+ for (int i = 0; i < index; i++) {
for (int j = 0; j < method_descr[i].length; j++) {
CPNameAndType descr = method_descr[i][j];
methodDescr[k] = descr.getIndex();
@@ -774,7 +780,9 @@ public class ClassBands extends BandSet
private int[] getInts(CPClass[] cpClasses) {
int[] ints = new int[cpClasses.length];
for (int i = 0; i < ints.length; i++) {
- ints[i] = cpClasses[i].getIndex();
+ if(cpClasses[i] != null) {
+ ints[i] = cpClasses[i].getIndex();
+ }
}
return ints;
}
@@ -999,6 +1007,24 @@ public class ClassBands extends BandSet
}
public void endOfMethod() {
+ if (tempMethodRVPA != null) {
+ method_RVPA_bands.addParameterAnnotation(tempMethodRVPA.numParams,
+ tempMethodRVPA.annoN, tempMethodRVPA.pairN,
+ tempMethodRVPA.typeRS, tempMethodRVPA.nameRU,
+ tempMethodRVPA.t, tempMethodRVPA.values,
+ tempMethodRVPA.caseArrayN, tempMethodRVPA.nestTypeRS,
+ tempMethodRVPA.nestNameRU, tempMethodRVPA.nestPairN);
+ tempMethodRVPA = null;
+ }
+ if (tempMethodRIPA != null) {
+ method_RIPA_bands.addParameterAnnotation(tempMethodRIPA.numParams,
+ tempMethodRIPA.annoN, tempMethodRIPA.pairN,
+ tempMethodRIPA.typeRS, tempMethodRIPA.nameRU,
+ tempMethodRIPA.t, tempMethodRIPA.values,
+ tempMethodRIPA.caseArrayN, tempMethodRIPA.nestTypeRS,
+ tempMethodRIPA.nestNameRU, tempMethodRIPA.nestPairN);
+ tempMethodRIPA = null;
+ }
if(codeFlags.size() > 0) {
long latestCodeFlag = ((Long)codeFlags.get(codeFlags.size() - 1)).longValue();
int latestLocalVariableTableN = codeLocalVariableTableN.get(codeLocalVariableTableN.size() - 1);
@@ -1327,26 +1353,57 @@ public class ClassBands extends BandSet
public void addParameterAnnotation(int parameter, String desc,
boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
if(visible) {
- method_RVPA_bands.addParameterAnnotation(parameter, desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
- Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
- if((flag.intValue() & (1<<23)) != 0) {
- method_RVPA_bands.incrementAnnoN();
- } else {
- method_RVPA_bands.newEntryInAnnoN();
+ if(tempMethodRVPA == null) {
+ tempMethodRVPA = new TempParamAnnotation(numMethodArgs);
+ tempMethodRVPA.addParameterAnnotation(parameter, desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
}
+ Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
tempMethodFlags.add(new Long(flag.longValue() | (1<<23)));
} else {
- method_RIPA_bands.addParameterAnnotation(parameter, desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
- Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
- if((flag.longValue() & (1<<24)) != 0) {
- method_RIPA_bands.incrementAnnoN();
- } else {
- method_RIPA_bands.newEntryInAnnoN();
+ if(tempMethodRIPA == null) {
+ tempMethodRIPA = new TempParamAnnotation(numMethodArgs);
+ tempMethodRIPA.addParameterAnnotation(parameter, desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
}
+ Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
tempMethodFlags.add(new Long(flag.longValue() | (1<<24)));
}
}
+ private static class TempParamAnnotation {
+
+ int numParams;
+ int[] annoN;
+ IntList pairN = new IntList();
+ List typeRS = new ArrayList();
+ List nameRU = new ArrayList();
+ List t = new ArrayList();
+ List values = new ArrayList();
+ List caseArrayN = new ArrayList();
+ List nestTypeRS = new ArrayList();
+ List nestNameRU = new ArrayList();
+ List nestPairN = new ArrayList();
+
+ public TempParamAnnotation (int numParams) {
+ this.numParams = numParams;
+ annoN = new int[numParams];
+ }
+
+ public void addParameterAnnotation(int parameter, String desc,
+ List nameRU, List t, List values, List caseArrayN,
+ List nestTypeRS, List nestNameRU, List nestPairN) {
+ annoN[parameter]++;
+ typeRS.add(desc);
+ pairN.add(nameRU.size());
+ this.nameRU.addAll(nameRU);
+ this.t.addAll(t);
+ this.values.addAll(values);
+ this.caseArrayN.addAll(caseArrayN);
+ this.nestTypeRS.addAll(nestTypeRS);
+ this.nestNameRU.addAll(nestNameRU);
+ this.nestPairN.addAll(nestPairN);
+ }
+ }
+
public void addAnnotation(int context, String desc, boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
switch (context) {
case MetadataBandGroup.CONTEXT_CLASS:
@@ -1548,6 +1605,12 @@ public class ClassBands extends BandSet
tempFieldFlags.clear();
tempMethodDesc.clear();
tempMethodFlags.clear();
- index--;
+ if(index > 0) {
+ index--;
+ }
+ }
+
+ public int numClassesProcessed() {
+ return index;
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Tue Sep 21 19:45:57 2010
@@ -151,28 +151,28 @@ public class CpBands extends BandSet {
cpUtf8BigChars[i][j] = ((Character) bigChars.remove(0)).charValue();
}
}
-
+
byte[] encodedBand = encodeBandInt("cpUtf8Prefix", cpUtf8Prefix, Codec.DELTA5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cpUtf8Prefix[" + cpUtf8Prefix.length + "]");
-
+
encodedBand = encodeBandInt("cpUtf8Suffix", cpUtf8Suffix, Codec.UNSIGNED5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cpUtf8Suffix[" + cpUtf8Suffix.length + "]");
-
+
encodedBand = encodeBandInt("cpUtf8Chars", cpUtf8Chars, Codec.CHAR3);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cpUtf8Chars[" + cpUtf8Chars.length + "]");
-
+
encodedBand = encodeBandInt("cpUtf8BigSuffix", cpUtf8BigSuffix,
Codec.DELTA5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cpUtf8BigSuffix[" + cpUtf8BigSuffix.length + "]");
-
+
for (int i = 0; i < cpUtf8BigChars.length; i++) {
encodedBand = encodeBandInt("cpUtf8BigChars " + i,
cpUtf8BigChars[i], Codec.DELTA5);
@@ -238,7 +238,7 @@ public class CpBands extends BandSet {
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cp_Long_hi[" + highBits.length + "]");
-
+
encodedBand = encodeBandInt("cp_Long_lo", loBits, Codec.DELTA5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
@@ -262,7 +262,7 @@ public class CpBands extends BandSet {
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cp_Double_hi[" + highBits.length + "]");
-
+
encodedBand = encodeBandInt("cp_Double_lo", loBits, Codec.DELTA5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
@@ -317,13 +317,13 @@ public class CpBands extends BandSet {
for (int j = 0; j < cpSignatureClasses.length; j++) {
cpSignatureClasses[j] = ((CPClass) classes.get(j)).getIndex();
}
-
+
byte[] encodedBand = encodeBandInt("cpSignatureForm", cpSignatureForm,
Codec.DELTA5);
out.write(encodedBand);
PackingUtils.log("Wrote " + encodedBand.length
+ " bytes from cpSignatureForm[" + cpSignatureForm.length + "]");
-
+
encodedBand = encodeBandInt("cpSignatureClasses", cpSignatureClasses,
Codec.UDELTA5);
out.write(encodedBand);
@@ -499,14 +499,6 @@ public class CpBands extends BandSet {
return cpUtf8;
}
- public void addCPNameAndType(String name, String signature) {
- getCPNameAndType(name, signature);
- }
-
- public void addCPSignature(String signature) {
- getCPSignature(signature);
- }
-
public CPSignature getCPSignature(String signature) {
if(signature == null) {
return null;
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/FileBands.java Tue Sep 21 19:45:57 2010
@@ -22,7 +22,6 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
-import java.util.TimeZone;
import org.apache.harmony.pack200.Archive.PackingFile;
import org.apache.harmony.pack200.Archive.SegmentUnit;
@@ -41,11 +40,16 @@ public class FileBands extends BandSet {
private final long[] file_size;
private final int[] file_options;
private final byte[][] file_bits;
+ private final List fileList;
+ private final PackingOptions options;
+ private final CpBands cpBands;
public FileBands(CpBands cpBands, SegmentHeader segmentHeader,
PackingOptions options, SegmentUnit segmentUnit, int effort) {
super(effort, segmentHeader);
- List fileList = segmentUnit.getFileList();
+ fileList = segmentUnit.getFileList();
+ this.options = options;
+ this.cpBands = cpBands;
int size = fileList.size();
fileName = new CPUTF8[size];
file_modtime = new int[size];
@@ -88,7 +92,7 @@ public class FileBands extends BandSet {
totalSize += file_size[i];
// update modification time
- modtime = (packingFile.getModtime() + TimeZone.getDefault().getRawOffset()) / 1000L;
+ modtime = (packingFile.getModtime()) / 1000L;
file_modtime[i] = (int) (modtime - archiveModtime);
if (isLatest && latestModtime < file_modtime[i]) {
latestModtime = file_modtime[i];
@@ -112,6 +116,14 @@ public class FileBands extends BandSet {
public void finaliseBands() {
file_name = new int[fileName.length];
for (int i = 0; i < file_name.length; i++) {
+ if (fileName[i].equals(cpBands.getCPUtf8(""))) {
+ PackingFile packingFile = (PackingFile) fileList.get(i);
+ String name = packingFile.getName();
+ if (options.isPassFile(name)) {
+ fileName[i] = cpBands.getCPUtf8(name);
+ file_options[i] &= (1 << 1) ^ 0xFFFFFFFF;
+ }
+ }
file_name[i] = fileName[i].getIndex();
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java Tue Sep 21 19:45:57 2010
@@ -170,10 +170,6 @@ public class IcBands extends BandSet {
return false;
}
- public int hashCode() {
- return (C.hashCode() * 37) + F;
- }
-
public String toString() {
return C.toString();
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java Tue Sep 21 19:45:57 2010
@@ -250,4 +250,11 @@ public class IntList {
return result;
}
+ public void addAll(IntList list) {
+ growAtEnd(list.size());
+ for (int i = 0; i < list.size(); i++) {
+ add(list.get(i));
+ }
+ }
+
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/MetadataBandGroup.java Tue Sep 21 19:45:57 2010
@@ -252,9 +252,69 @@ public class MetadataBandGroup extends B
* @param nestNameRU
* @param nestPairN
*/
- public void addParameterAnnotation(int parameter, String desc, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
- param_NB.add(parameter);
- addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+ public void addParameterAnnotation(int numParams, int[] annoN, IntList pairN, List typeRS, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
+ param_NB.add(numParams);
+ for (int i = 0; i < annoN.length; i++) {
+ anno_N.add(annoN[i]);
+ }
+ pair_N.addAll(pairN);
+ for (Iterator iterator = typeRS.iterator(); iterator.hasNext();) {
+ String desc = (String) iterator.next();
+ type_RS.add(cpBands.getCPSignature(desc));
+ }
+ for (Iterator iterator = nameRU.iterator(); iterator.hasNext();) {
+ String name = (String) iterator.next();
+ name_RU.add(cpBands.getCPUtf8(name));
+ }
+ Iterator valuesIterator = values.iterator();
+ for (Iterator iterator = t.iterator(); iterator.hasNext();) {
+ String tag = (String) iterator.next();
+ T.add(tag);
+ if (tag.equals("B") || tag.equals("C") || tag.equals("I")
+ || tag.equals("S") || tag.equals("Z")) {
+ Integer value = (Integer)valuesIterator.next();
+ caseI_KI.add(cpBands.getConstant(value));
+ } else if (tag.equals("D")) {
+ Double value = (Double)valuesIterator.next();
+ caseD_KD.add(cpBands.getConstant(value));
+ } else if (tag.equals("F")) {
+ Float value = (Float)valuesIterator.next();
+ caseF_KF.add(cpBands.getConstant(value));
+ } else if (tag.equals("J")) {
+ Long value = (Long)valuesIterator.next();
+ caseJ_KJ.add(cpBands.getConstant(value));
+ } else if (tag.equals("c")) {
+ String value = (String)valuesIterator.next();
+ casec_RS.add(cpBands.getCPSignature(value));
+ } else if (tag.equals("e")) {
+ String value = (String)valuesIterator.next();
+ String value2 = (String)valuesIterator.next();
+ caseet_RS.add(cpBands.getCPSignature(value));
+ caseec_RU.add(cpBands.getCPUtf8(value2));
+ } else if (tag.equals("s")) {
+ String value = (String)valuesIterator.next();
+ cases_RU.add(cpBands.getCPUtf8(value));
+ }
+ // do nothing here for [ or @ (handled below)
+ }
+ for (Iterator iterator = caseArrayN.iterator(); iterator.hasNext();) {
+ int arraySize = ((Integer)iterator.next()).intValue();
+ casearray_N.add(arraySize);
+ numBackwardsCalls += arraySize;
+ }
+ for (Iterator iterator = nestTypeRS.iterator(); iterator.hasNext();) {
+ String type = (String) iterator.next();
+ nesttype_RS.add(cpBands.getCPSignature(type));
+ }
+ for (Iterator iterator = nestNameRU.iterator(); iterator.hasNext();) {
+ String name = (String) iterator.next();
+ nestname_RU.add(cpBands.getCPUtf8(name));
+ }
+ for (Iterator iterator = nestPairN.iterator(); iterator.hasNext();) {
+ Integer numPairs = (Integer) iterator.next();
+ nestpair_N.add(numPairs.intValue());
+ numBackwardsCalls += numPairs.intValue();
+ }
}
/**
@@ -314,17 +374,17 @@ public class MetadataBandGroup extends B
casearray_N.add(arraySize);
numBackwardsCalls += arraySize;
}
- for (Iterator iterator = nesttype_RS.iterator(); iterator.hasNext();) {
+ for (Iterator iterator = nestTypeRS.iterator(); iterator.hasNext();) {
String type = (String) iterator.next();
nesttype_RS.add(cpBands.getCPSignature(type));
}
- for (Iterator iterator = nestname_RU.iterator(); iterator.hasNext();) {
+ for (Iterator iterator = nestNameRU.iterator(); iterator.hasNext();) {
String name = (String) iterator.next();
nestname_RU.add(cpBands.getCPUtf8(name));
}
for (Iterator iterator = nestPairN.iterator(); iterator.hasNext();) {
Integer numPairs = (Integer) iterator.next();
- nestPairN.add(numPairs);
+ nestpair_N.add(numPairs.intValue());
numBackwardsCalls += numPairs.intValue();
}
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttribute.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttribute.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttribute.java Tue Sep 21 19:45:57 2010
@@ -112,13 +112,13 @@ public class NewAttribute extends Attrib
public boolean isUnknown(int context) {
switch(context) {
case AttributeDefinitionBands.CONTEXT_CLASS:
- return contextClass;
+ return !contextClass;
case AttributeDefinitionBands.CONTEXT_METHOD:
- return contextMethod;
+ return !contextMethod;
case AttributeDefinitionBands.CONTEXT_FIELD:
- return contextField;
+ return !contextField;
case AttributeDefinitionBands.CONTEXT_CODE:
- return contextCode;
+ return !contextCode;
}
return false;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java Tue Sep 21 19:45:57 2010
@@ -155,7 +155,7 @@ public class NewAttributeBands extends B
}
}
} else { // Backwards call
- for (int k = i; k >= 0; k--) {
+ for (int k = i - 1; k >= 0; k--) {
AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements
.get(k);
if (el instanceof Callable) {
@@ -657,13 +657,10 @@ public class NewAttributeBands extends B
private List band;
- private final int length;
-
private boolean nullsAllowed = false;
public Reference(String tag) {
this.tag = tag;
- length = getLength(tag.charAt(tag.length() - 1));
nullsAllowed = tag.indexOf('N') != -1;
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java Tue Sep 21 19:45:57 2010
@@ -16,9 +16,6 @@
*/
package org.apache.harmony.pack200;
-import java.io.IOException;
-import java.io.InputStream;
-
import org.objectweb.asm.ClassReader;
/**
@@ -40,32 +37,6 @@ public class Pack200ClassReader extends
super(b);
}
- /**
- * @param is
- * the input stream of class file
- * @throws IOException
- */
- public Pack200ClassReader(InputStream is) throws IOException {
- super(is);
- }
-
- /**
- * @param name
- * @throws IOException
- */
- public Pack200ClassReader(String name) throws IOException {
- super(name);
- }
-
- /**
- * @param b
- * @param off
- * @param len
- */
- public Pack200ClassReader(byte[] b, int off, int len) {
- super(b, off, len);
- }
-
public int readUnsignedShort(int index) {
// Doing this to check whether last load-constant instruction was ldc (18) or ldc_w (19)
// TODO: Assess whether this impacts on performance
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200Exception.java Tue Sep 21 19:45:57 2010
@@ -33,26 +33,4 @@ public class Pack200Exception extends Ex
super(message);
}
- /**
- * Create a new Pack200 exception with the given message and cause
- *
- * @param message
- * the text message to display
- * @param cause
- * the {@link Throwable} that caused this problem
- */
- public Pack200Exception(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Create a new Pack200 exception with the given cause
- *
- * @param cause
- * the {@link Throwable} that caused this problem
- */
- public Pack200Exception(Throwable cause) {
- super(cause);
- }
-
}
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PackingOptions.java Tue Sep 21 19:45:57 2010
@@ -35,7 +35,6 @@ public class PackingOptions {
public static final String KEEP = "keep";
// All options are initially set to their defaults
- private boolean repack = false;
private boolean gzip = true;
private boolean stripDebug = false;
private boolean keepFileOrder = true;
@@ -50,19 +49,10 @@ public class PackingOptions {
private Map methodAttributeActions;
private Map codeAttributeActions;
private boolean verbose = false;
- private boolean quiet = true;
private String logFile;
private Attribute[] unknownAttributeTypes;
- public boolean isRepack() {
- return repack;
- }
-
- public void setRepack(boolean repack) {
- this.repack = repack;
- }
-
public boolean isGzip() {
return gzip;
}
@@ -128,6 +118,14 @@ public class PackingOptions {
}
public void setDeflateHint(String deflateHint) {
+ if (!KEEP.equals(deflateHint)
+ && !"true".equals(deflateHint)
+ && !"false".equals(deflateHint)) {
+ throw new IllegalArgumentException(
+ "Bad argument: -H "
+ + deflateHint
+ + " ? deflate hint should be either true, false or keep (default)");
+ }
this.deflateHint = deflateHint;
}
@@ -245,12 +243,8 @@ public class PackingOptions {
this.verbose = verbose;
}
- public boolean isQuiet() {
- return quiet;
- }
-
public void setQuiet(boolean quiet) {
- this.quiet = quiet;
+ this.verbose = !quiet;
}
public String getLogFile() {
@@ -323,6 +317,9 @@ public class PackingOptions {
}
public String getUnknownClassAttributeAction(String type) {
+ if (classAttributeActions == null) {
+ return unknownAttributeAction;
+ }
String action = (String) classAttributeActions.get(type);
if(action == null) {
action = unknownAttributeAction;
@@ -331,6 +328,9 @@ public class PackingOptions {
}
public String getUnknownMethodAttributeAction(String type) {
+ if (methodAttributeActions == null) {
+ return unknownAttributeAction;
+ }
String action = (String) methodAttributeActions.get(type);
if(action == null) {
action = unknownAttributeAction;
@@ -339,6 +339,9 @@ public class PackingOptions {
}
public String getUnknownFieldAttributeAction(String type) {
+ if (fieldAttributeActions == null) {
+ return unknownAttributeAction;
+ }
String action = (String) fieldAttributeActions.get(type);
if(action == null) {
action = unknownAttributeAction;
@@ -347,6 +350,9 @@ public class PackingOptions {
}
public String getUnknownCodeAttributeAction(String type) {
+ if (codeAttributeActions == null) {
+ return unknownAttributeAction;
+ }
String action = (String) codeAttributeActions.get(type);
if(action == null) {
action = unknownAttributeAction;
Modified: harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java?rev=999573&r1=999572&r2=999573&view=diff
==============================================================================
--- harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java (original)
+++ harmony/enhanced/java/branches/mrh/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/PopulationCodec.java Tue Sep 21 19:45:57 2010
@@ -167,8 +167,4 @@ public class PopulationCodec extends Cod
public Codec getTokenCodec() {
return tokenCodec;
}
-
- public int getL() {
- return l;
- }
}