summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnu/java/nio/charset/ByteCharset.java167
-rw-r--r--gnu/java/nio/charset/Cp424.java73
-rw-r--r--gnu/java/nio/charset/Cp437.java6
-rw-r--r--gnu/java/nio/charset/Cp737.java6
-rw-r--r--gnu/java/nio/charset/Cp775.java6
-rw-r--r--gnu/java/nio/charset/Cp850.java6
-rw-r--r--gnu/java/nio/charset/Cp852.java6
-rw-r--r--gnu/java/nio/charset/Cp855.java7
-rw-r--r--gnu/java/nio/charset/Cp857.java7
-rw-r--r--gnu/java/nio/charset/Cp860.java7
-rw-r--r--gnu/java/nio/charset/Cp861.java7
-rw-r--r--gnu/java/nio/charset/Cp862.java7
-rw-r--r--gnu/java/nio/charset/Cp863.java7
-rw-r--r--gnu/java/nio/charset/Cp864.java7
-rw-r--r--gnu/java/nio/charset/Cp865.java7
-rw-r--r--gnu/java/nio/charset/Cp866.java7
-rw-r--r--gnu/java/nio/charset/Cp869.java7
-rw-r--r--gnu/java/nio/charset/Cp874.java6
-rw-r--r--gnu/java/nio/charset/EncodingHelper.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_1.java63
-rw-r--r--gnu/java/nio/charset/ISO_8859_13.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_15.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_2.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_3.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_4.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_5.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_6.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_7.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_8.java5
-rw-r--r--gnu/java/nio/charset/ISO_8859_9.java5
-rw-r--r--gnu/java/nio/charset/KOI_8.java5
-rw-r--r--gnu/java/nio/charset/MS874.java6
-rw-r--r--gnu/java/nio/charset/MacCentralEurope.java6
-rw-r--r--gnu/java/nio/charset/MacCroatian.java6
-rw-r--r--gnu/java/nio/charset/MacCyrillic.java6
-rw-r--r--gnu/java/nio/charset/MacDingbat.java6
-rw-r--r--gnu/java/nio/charset/MacGreek.java6
-rw-r--r--gnu/java/nio/charset/MacIceland.java6
-rw-r--r--gnu/java/nio/charset/MacRoman.java6
-rw-r--r--gnu/java/nio/charset/MacRomania.java6
-rw-r--r--gnu/java/nio/charset/MacSymbol.java6
-rw-r--r--gnu/java/nio/charset/MacThai.java6
-rw-r--r--gnu/java/nio/charset/MacTurkish.java6
-rw-r--r--gnu/java/nio/charset/Provider.java18
-rw-r--r--gnu/java/nio/charset/US_ASCII.java68
-rw-r--r--gnu/java/nio/charset/Windows1250.java5
-rw-r--r--gnu/java/nio/charset/Windows1251.java5
-rw-r--r--gnu/java/nio/charset/Windows1252.java5
-rw-r--r--gnu/java/nio/charset/Windows1253.java5
-rw-r--r--gnu/java/nio/charset/Windows1254.java5
-rw-r--r--gnu/java/nio/charset/Windows1255.java5
-rw-r--r--gnu/java/nio/charset/Windows1256.java5
-rw-r--r--gnu/java/nio/charset/Windows1257.java5
-rw-r--r--gnu/java/nio/charset/Windows1258.java5
54 files changed, 275 insertions, 397 deletions
diff --git a/gnu/java/nio/charset/ByteCharset.java b/gnu/java/nio/charset/ByteCharset.java
index e20254829..043c804b7 100644
--- a/gnu/java/nio/charset/ByteCharset.java
+++ b/gnu/java/nio/charset/ByteCharset.java
@@ -45,32 +45,34 @@ import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
/**
- * A generic encoding framework for single-byte encodings,
- * utilizing a look-up table.
+ * A generic encoding framework for single-byte encodings, utilizing a look-up
+ * table.
+ *
+ * This replaces the gnu.java.io.EncoderEightBitLookup class, created by Aron
+ * Renn.
*
- * This replaces the gnu.java.io.EncoderEightBitLookup class,
- * created by Aron Renn.
- *
* @author Sven de Marothy
+ * @modified Ian Rogers
*/
abstract class ByteCharset extends Charset
{
- protected char[] lookupTable;
- /**
- * Char to signify the character in the table is undefined
- */
- protected static final char NONE = (char)0xFFFD;
+ protected final char[] lookupTable;
+ /**
+ * Char to signify the character in the table is undefined
+ */
+ protected static final char NONE = (char) 0xFFFD;
- ByteCharset (String canonicalName, String[] aliases)
+ ByteCharset(String canonicalName, String[] aliases, char[] lookup)
{
- super (canonicalName, aliases);
+ super(canonicalName, aliases);
+ lookupTable = lookup;
}
/**
- * Most western charsets include ASCII, but this should
- * be overloaded for others.
+ * Most western charsets include ASCII, but this should be overloaded for
+ * others.
*/
- public boolean contains (Charset cs)
+ public boolean contains(Charset cs)
{
return cs instanceof US_ASCII || (cs.getClass() == getClass());
}
@@ -80,83 +82,91 @@ abstract class ByteCharset extends Charset
return lookupTable;
}
- public CharsetDecoder newDecoder ()
+ public CharsetDecoder newDecoder()
{
- return new Decoder (this);
+ return new Decoder(this);
}
- public CharsetEncoder newEncoder ()
+ public CharsetEncoder newEncoder()
{
- return new Encoder (this);
+ return new Encoder(this);
}
private static final class Decoder extends CharsetDecoder
{
- private char[] lookup;
-
+ /** Lookup of byte to char mappings */
+ private final char[] lookup;
+
+ /** Helper to decode loops */
+ private final ByteDecodeLoopHelper helper = new ByteDecodeLoopHelper()
+ {
+ protected boolean isMappable(byte b)
+ {
+ return lookup[(int) (b & 0xFF)] != NONE;
+ }
+ protected char mapToChar(byte b)
+ {
+ return lookup[(int) (b & 0xFF)];
+ }
+ };
+
// Package-private to avoid a trampoline constructor.
- Decoder (ByteCharset cs)
+ Decoder(ByteCharset cs)
{
- super (cs, 1.0f, 1.0f);
+ super(cs, 1.0f, 1.0f);
lookup = cs.getLookupTable();
}
- protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out)
+ protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- byte b = in.get ();
- char c;
-
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- if((c = lookup[(int) (b & 0xFF)]) == NONE)
- {
- in.position (in.position () - 1);
- return CoderResult.unmappableForLength (1);
- }
- out.put (c);
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.decodeLoop(in, out);
}
}
private static final class Encoder extends CharsetEncoder
{
- private byte[] lookup;
-
+ /** Lookup of char to byte mappings */
+ private final byte[] lookup;
+
+ /** Helper to encode loops */
+ private final ByteEncodeLoopHelper helper = new ByteEncodeLoopHelper()
+ {
+ protected boolean isMappable(char c)
+ {
+ return canEncode(c);
+ }
+ protected byte mapToByte(char c)
+ {
+ return lookup[c];
+ }
+ };
+
// Package-private to avoid a trampoline constructor.
- Encoder (ByteCharset cs)
+ Encoder(ByteCharset cs)
{
- super (cs, 1.0f, 1.0f);
+ super(cs, 1.0f, 1.0f);
char[] lookup_table = cs.getLookupTable();
// Create the inverse look-up table.
- // determine required size of encoding_table:
- int max = 0;
+ // determine required size of encoding_table:
+ int max = 0;
for (int i = 0; i < lookup_table.length; i++)
- {
- int c = (int)lookup_table[i];
- max = (c > max && c < NONE) ? c : max;
- }
+ {
+ int c = (int) lookup_table[i];
+ max = (c > max && c < NONE) ? c : max;
+ }
+
+ lookup = new byte[max + 1];
- lookup = new byte[max+1];
-
for (int i = 0; i < lookup_table.length; i++)
- {
- int c = (int)lookup_table[i];
- if (c != 0 && c < NONE)
- {
- lookup[c] = (byte)i;
- }
- }
+ {
+ int c = (int) lookup_table[i];
+ if (c != 0 && c < NONE)
+ {
+ lookup[c] = (byte) i;
+ }
+ }
}
public boolean canEncode(char c)
@@ -169,38 +179,15 @@ abstract class ByteCharset extends Charset
{
for (int i = 0; i < cs.length(); ++i)
{
- if (! canEncode(cs.charAt(i)))
+ if (!canEncode(cs.charAt(i)))
return false;
}
return true;
}
- protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
+ protected CoderResult encodeLoop(CharBuffer in, ByteBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- int c = (int)in.get ();
-
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- // lookup byte encoding
- byte b = (c < lookup.length) ? lookup[c] : (byte)0;
-
- if ((int)b != 0 || (int)c == 0)
- {
- out.put (b);
- } else {
- in.position (in.position () - 1);
- return CoderResult.unmappableForLength (1);
- }
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.encodeLoop(in, out);
}
}
}
diff --git a/gnu/java/nio/charset/Cp424.java b/gnu/java/nio/charset/Cp424.java
index 9733a76a4..44e1eba4f 100644
--- a/gnu/java/nio/charset/Cp424.java
+++ b/gnu/java/nio/charset/Cp424.java
@@ -37,53 +37,50 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp424 extends ByteCharset
+public final class Cp424 extends ByteCharset
{
/**
* This is the lookup table for this encoding
*/
- private static final char[] lookup =
+ private static final char[] lookup =
{
- 0x0000, 0x0001, 0x0002, 0x0003, 0x009C, 0x0009, 0x0086, 0x007F,
- 0x0097, 0x008D, 0x008E, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
- 0x0010, 0x0011, 0x0012, 0x0013, 0x009D, 0x0085, 0x0008, 0x0087,
- 0x0018, 0x0019, 0x0092, 0x008F, 0x001C, 0x001D, 0x001E, 0x001F,
- 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x000A, 0x0017, 0x001B,
- 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x0005, 0x0006, 0x0007,
- 0x0090, 0x0091, 0x0016, 0x0093, 0x0094, 0x0095, 0x0096, 0x0004,
- 0x0098, 0x0099, 0x009A, 0x009B, 0x0014, 0x0015, 0x009E, 0x001A,
- 0x0020, 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6,
- 0x05D7, 0x05D8, 0x00A2, 0x002E, 0x003C, 0x0028, 0x002B, 0x007C,
- 0x0026, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
- 0x05E0, 0x05E1, 0x0021, 0x0024, 0x002A, 0x0029, 0x003B, 0x00AC,
- 0x002D, 0x002F, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
- 0x05E8, 0x05E9, 0x00A6, 0x002C, 0x0025, 0x005F, 0x003E, 0x003F,
- NONE, 0x05EA, NONE, NONE, 0x00A0, NONE, NONE, NONE,
- 0x2017, 0x0060, 0x003A, 0x0023, 0x0040, 0x0027, 0x003D, 0x0022,
- NONE, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
- 0x0068, 0x0069, 0x00AB, 0x00BB, NONE, NONE, NONE, 0x00B1,
- 0x00B0, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070,
- 0x0071, 0x0072, NONE, NONE, NONE, 0x00B8, NONE, 0x00A4,
- 0x00B5, 0x007E, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078,
- 0x0079, 0x007A, NONE, NONE, NONE, NONE, NONE, 0x00AE,
- 0x005E, 0x00A3, 0x00A5, 0x00B7, 0x00A9, 0x00A7, 0x00B6, 0x00BC,
- 0x00BD, 0x00BE, 0x005B, 0x005D, 0x00AF, 0x00A8, 0x00B4, 0x00D7,
- 0x007B, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
- 0x0048, 0x0049, 0x00AD, NONE, NONE, NONE, NONE, NONE,
- 0x007D, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050,
- 0x0051, 0x0052, 0x00B9, NONE, NONE, NONE, NONE, NONE,
- 0x005C, 0x00F7, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
- 0x0059, 0x005A, 0x00B2, NONE, NONE, NONE, NONE, NONE,
- 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
+ 0x0000, 0x0001, 0x0002, 0x0003, 0x009C, 0x0009, 0x0086, 0x007F,
+ 0x0097, 0x008D, 0x008E, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
+ 0x0010, 0x0011, 0x0012, 0x0013, 0x009D, 0x0085, 0x0008, 0x0087,
+ 0x0018, 0x0019, 0x0092, 0x008F, 0x001C, 0x001D, 0x001E, 0x001F,
+ 0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x000A, 0x0017, 0x001B,
+ 0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x0005, 0x0006, 0x0007,
+ 0x0090, 0x0091, 0x0016, 0x0093, 0x0094, 0x0095, 0x0096, 0x0004,
+ 0x0098, 0x0099, 0x009A, 0x009B, 0x0014, 0x0015, 0x009E, 0x001A,
+ 0x0020, 0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6,
+ 0x05D7, 0x05D8, 0x00A2, 0x002E, 0x003C, 0x0028, 0x002B, 0x007C,
+ 0x0026, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
+ 0x05E0, 0x05E1, 0x0021, 0x0024, 0x002A, 0x0029, 0x003B, 0x00AC,
+ 0x002D, 0x002F, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
+ 0x05E8, 0x05E9, 0x00A6, 0x002C, 0x0025, 0x005F, 0x003E, 0x003F,
+ NONE, 0x05EA, NONE, NONE, 0x00A0, NONE, NONE, NONE,
+ 0x2017, 0x0060, 0x003A, 0x0023, 0x0040, 0x0027, 0x003D, 0x0022,
+ NONE, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
+ 0x0068, 0x0069, 0x00AB, 0x00BB, NONE, NONE, NONE, 0x00B1,
+ 0x00B0, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F, 0x0070,
+ 0x0071, 0x0072, NONE, NONE, NONE, 0x00B8, NONE, 0x00A4,
+ 0x00B5, 0x007E, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078,
+ 0x0079, 0x007A, NONE, NONE, NONE, NONE, NONE, 0x00AE,
+ 0x005E, 0x00A3, 0x00A5, 0x00B7, 0x00A9, 0x00A7, 0x00B6, 0x00BC,
+ 0x00BD, 0x00BE, 0x005B, 0x005D, 0x00AF, 0x00A8, 0x00B4, 0x00D7,
+ 0x007B, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
+ 0x0048, 0x0049, 0x00AD, NONE, NONE, NONE, NONE, NONE,
+ 0x007D, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, 0x0050,
+ 0x0051, 0x0052, 0x00B9, NONE, NONE, NONE, NONE, NONE,
+ 0x005C, 0x00F7, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
+ 0x0059, 0x005A, 0x00B2, NONE, NONE, NONE, NONE, NONE,
+ 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x00B3, NONE, NONE, NONE, NONE, 0x009F
};
- public Cp424()
- {
- super("Cp424", new String[] {
- });
- lookupTable = lookup;
+ public Cp424() {
+ super("Cp424", new String[] {}, lookup);
}
} // class Cp424
diff --git a/gnu/java/nio/charset/Cp437.java b/gnu/java/nio/charset/Cp437.java
index d6083579d..e38a48257 100644
--- a/gnu/java/nio/charset/Cp437.java
+++ b/gnu/java/nio/charset/Cp437.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp437 extends ByteCharset
+public final class Cp437 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp437 extends ByteCharset
public Cp437()
{
- super("Cp437", new String[] {
- });
- lookupTable = lookup;
+ super("Cp437", new String[]{}, lookup);
}
} // class Cp437
diff --git a/gnu/java/nio/charset/Cp737.java b/gnu/java/nio/charset/Cp737.java
index 548da2191..2187987ea 100644
--- a/gnu/java/nio/charset/Cp737.java
+++ b/gnu/java/nio/charset/Cp737.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp737 extends ByteCharset
+public final class Cp737 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp737 extends ByteCharset
public Cp737()
{
- super("Cp737", new String[] {
- });
- lookupTable = lookup;
+ super("Cp737", new String[] {}, lookup);
}
} // class Cp737
diff --git a/gnu/java/nio/charset/Cp775.java b/gnu/java/nio/charset/Cp775.java
index 4d3f1c36c..f2fba4356 100644
--- a/gnu/java/nio/charset/Cp775.java
+++ b/gnu/java/nio/charset/Cp775.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp775 extends ByteCharset
+public final class Cp775 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp775 extends ByteCharset
public Cp775()
{
- super("Cp775", new String[] {
- });
- lookupTable = lookup;
+ super("Cp775", new String[] {}, lookup);
}
} // class Cp775
diff --git a/gnu/java/nio/charset/Cp850.java b/gnu/java/nio/charset/Cp850.java
index 9122105ad..48d4fb344 100644
--- a/gnu/java/nio/charset/Cp850.java
+++ b/gnu/java/nio/charset/Cp850.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp850 extends ByteCharset
+public final class Cp850 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp850 extends ByteCharset
public Cp850()
{
- super("Cp850", new String[] {
- });
- lookupTable = lookup;
+ super("Cp850", new String[] {}, lookup);
}
} // class Cp850
diff --git a/gnu/java/nio/charset/Cp852.java b/gnu/java/nio/charset/Cp852.java
index a859530a8..c550944b5 100644
--- a/gnu/java/nio/charset/Cp852.java
+++ b/gnu/java/nio/charset/Cp852.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp852 extends ByteCharset
+public final class Cp852 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp852 extends ByteCharset
public Cp852()
{
- super("Cp852", new String[] {
- });
- lookupTable = lookup;
+ super("Cp852", new String[] {}, lookup);
}
} // class Cp852
diff --git a/gnu/java/nio/charset/Cp855.java b/gnu/java/nio/charset/Cp855.java
index fbec999c7..141e891b6 100644
--- a/gnu/java/nio/charset/Cp855.java
+++ b/gnu/java/nio/charset/Cp855.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp855 extends ByteCharset
+public final class Cp855 extends ByteCharset
{
/**
@@ -81,10 +81,7 @@ public class Cp855 extends ByteCharset
public Cp855()
{
- super("Cp855", new String[] {
- "cp-855",
- });
- lookupTable = lookup;
+ super("Cp855", new String[] {"cp-855",}, lookup);
}
} // class Cp855
diff --git a/gnu/java/nio/charset/Cp857.java b/gnu/java/nio/charset/Cp857.java
index 78f8dbd2d..b517b0393 100644
--- a/gnu/java/nio/charset/Cp857.java
+++ b/gnu/java/nio/charset/Cp857.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp857 extends ByteCharset
+public final class Cp857 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp857 extends ByteCharset
public Cp857()
{
- super("Cp857", new String[] {
- "cp-857"
- });
- lookupTable = lookup;
+ super("Cp857", new String[] {"cp-857"}, lookup);
}
} // class Cp857
diff --git a/gnu/java/nio/charset/Cp860.java b/gnu/java/nio/charset/Cp860.java
index e3c7f46b8..58a396446 100644
--- a/gnu/java/nio/charset/Cp860.java
+++ b/gnu/java/nio/charset/Cp860.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp860 extends ByteCharset
+public final class Cp860 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp860 extends ByteCharset
public Cp860()
{
- super("Cp860", new String[] {
- "cp-860"
- });
- lookupTable = lookup;
+ super("Cp860", new String[] {"cp-860"}, lookup);
}
} // class Cp860
diff --git a/gnu/java/nio/charset/Cp861.java b/gnu/java/nio/charset/Cp861.java
index 6e17ea2e8..cf5210d0a 100644
--- a/gnu/java/nio/charset/Cp861.java
+++ b/gnu/java/nio/charset/Cp861.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp861 extends ByteCharset
+public final class Cp861 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp861 extends ByteCharset
public Cp861()
{
- super("Cp861", new String[] {
- "cp-861"
- });
- lookupTable = lookup;
+ super("Cp861", new String[] {"cp-861"}, lookup);
}
} // class Cp861
diff --git a/gnu/java/nio/charset/Cp862.java b/gnu/java/nio/charset/Cp862.java
index ccd74fa9d..f66118021 100644
--- a/gnu/java/nio/charset/Cp862.java
+++ b/gnu/java/nio/charset/Cp862.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp862 extends ByteCharset
+public final class Cp862 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp862 extends ByteCharset
public Cp862()
{
- super("Cp862", new String[] {
- "Cp-862"
- });
- lookupTable = lookup;
+ super("Cp862", new String[] {"Cp-862"}, lookup);
}
} // class Cp862
diff --git a/gnu/java/nio/charset/Cp863.java b/gnu/java/nio/charset/Cp863.java
index 97812a6f6..03850234e 100644
--- a/gnu/java/nio/charset/Cp863.java
+++ b/gnu/java/nio/charset/Cp863.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp863 extends ByteCharset
+public final class Cp863 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp863 extends ByteCharset
public Cp863()
{
- super("Cp863", new String[] {
- "Cp-863"
- });
- lookupTable = lookup;
+ super("Cp863", new String[] {"Cp-863"}, lookup);
}
} // class Cp863
diff --git a/gnu/java/nio/charset/Cp864.java b/gnu/java/nio/charset/Cp864.java
index f136f43ec..028235dd3 100644
--- a/gnu/java/nio/charset/Cp864.java
+++ b/gnu/java/nio/charset/Cp864.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp864 extends ByteCharset
+public final class Cp864 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp864 extends ByteCharset
public Cp864()
{
- super("Cp864", new String[] {
- "Cp-864"
- });
- lookupTable = lookup;
+ super("Cp864", new String[] {"Cp-864"}, lookup);
}
} // class Cp864
diff --git a/gnu/java/nio/charset/Cp865.java b/gnu/java/nio/charset/Cp865.java
index a1332a74f..c723e80c9 100644
--- a/gnu/java/nio/charset/Cp865.java
+++ b/gnu/java/nio/charset/Cp865.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp865 extends ByteCharset
+public final class Cp865 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp865 extends ByteCharset
public Cp865()
{
- super("Cp865", new String[] {
- "Cp-865"
- });
- lookupTable = lookup;
+ super("Cp865", new String[] {"Cp-865"}, lookup);
}
} // class Cp865
diff --git a/gnu/java/nio/charset/Cp866.java b/gnu/java/nio/charset/Cp866.java
index ca6958949..103bca7c3 100644
--- a/gnu/java/nio/charset/Cp866.java
+++ b/gnu/java/nio/charset/Cp866.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp866 extends ByteCharset
+public final class Cp866 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp866 extends ByteCharset
public Cp866()
{
- super("Cp866", new String[] {
- "cp-866"
- });
- lookupTable = lookup;
+ super("Cp866", new String[] {"cp-866"}, lookup);
}
} // class Cp866
diff --git a/gnu/java/nio/charset/Cp869.java b/gnu/java/nio/charset/Cp869.java
index f5e052984..0632b3741 100644
--- a/gnu/java/nio/charset/Cp869.java
+++ b/gnu/java/nio/charset/Cp869.java
@@ -38,7 +38,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp869 extends ByteCharset
+public final class Cp869 extends ByteCharset
{
/**
@@ -82,10 +82,7 @@ public class Cp869 extends ByteCharset
public Cp869()
{
- super("Cp869", new String[] {
- "Cp-869"
- });
- lookupTable = lookup;
+ super("Cp869", new String[] {"Cp-869"}, lookup);
}
} // class Cp869
diff --git a/gnu/java/nio/charset/Cp874.java b/gnu/java/nio/charset/Cp874.java
index d81755c1e..f6e52c485 100644
--- a/gnu/java/nio/charset/Cp874.java
+++ b/gnu/java/nio/charset/Cp874.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class Cp874 extends ByteCharset
+public final class Cp874 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class Cp874 extends ByteCharset
public Cp874()
{
- super("Cp874", new String[] {
- });
- lookupTable = lookup;
+ super("Cp874", new String[] {}, lookup);
}
} // class Cp874
diff --git a/gnu/java/nio/charset/EncodingHelper.java b/gnu/java/nio/charset/EncodingHelper.java
index be7b4afe0..479b6e534 100644
--- a/gnu/java/nio/charset/EncodingHelper.java
+++ b/gnu/java/nio/charset/EncodingHelper.java
@@ -57,10 +57,10 @@ public class EncodingHelper
* Contains the mapping from java.io canonical names
* to java.nio canonical names.
*/
- private static HashMap canonicalNames;
+ private static final HashMap<String,String> canonicalNames;
static {
- canonicalNames = new HashMap();
+ canonicalNames = new HashMap<String,String>();
canonicalNames.put("US-ASCII", "ASCII");
canonicalNames.put("windows-1250", "Cp1250");
canonicalNames.put("windows-1251", "Cp1251");
@@ -94,7 +94,6 @@ public class EncodingHelper
*/
public static String getDefaultEncoding()
{
- String encoding;
try
{
return System.getProperty("file.encoding");
diff --git a/gnu/java/nio/charset/ISO_8859_1.java b/gnu/java/nio/charset/ISO_8859_1.java
index 558289583..19a538d9f 100644
--- a/gnu/java/nio/charset/ISO_8859_1.java
+++ b/gnu/java/nio/charset/ISO_8859_1.java
@@ -48,6 +48,7 @@ import java.nio.charset.CoderResult;
* ISO-8859-1 charset.
*
* @author Jesse Rosenstock
+ * @modified Ian Rogers
*/
final class ISO_8859_1 extends Charset
{
@@ -98,6 +99,19 @@ final class ISO_8859_1 extends Charset
private static final class Decoder extends CharsetDecoder
{
+ /** Helper to decode loops */
+ private static final ByteDecodeLoopHelper helper = new ByteDecodeLoopHelper()
+ {
+ protected boolean isMappable(byte b)
+ {
+ return true;
+ }
+ protected char mapToChar(byte b)
+ {
+ return (char)(b & 0xFF);
+ }
+ };
+
// Package-private to avoid a trampoline constructor.
Decoder (Charset cs)
{
@@ -106,26 +120,24 @@ final class ISO_8859_1 extends Charset
protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- byte b = in.get ();
-
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((char) (b & 0xFF));
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.decodeLoop(in, out);
}
}
private static final class Encoder extends CharsetEncoder
{
+ /** Helper to encode loops */
+ private static final ByteEncodeLoopHelper helper = new ByteEncodeLoopHelper()
+ {
+ protected boolean isMappable(char c)
+ {
+ return c <= 0xff;
+ }
+ protected byte mapToByte(char c)
+ {
+ return (byte)c;
+ }
+ };
// Package-private to avoid a trampoline constructor.
Encoder (Charset cs)
{
@@ -147,26 +159,7 @@ final class ISO_8859_1 extends Charset
protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- char c = in.get ();
-
- if (c > 0xFF)
- {
- in.position (in.position () - 1);
- return CoderResult.unmappableForLength (1);
- }
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((byte) c);
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.encodeLoop(in, out);
}
}
}
diff --git a/gnu/java/nio/charset/ISO_8859_13.java b/gnu/java/nio/charset/ISO_8859_13.java
index c10eef305..3bbd42f3b 100644
--- a/gnu/java/nio/charset/ISO_8859_13.java
+++ b/gnu/java/nio/charset/ISO_8859_13.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-13, ISO Latin-7 char set.
*/
-public class ISO_8859_13 extends ByteCharset
+public final class ISO_8859_13 extends ByteCharset
{
/**
@@ -96,8 +96,7 @@ public class ISO_8859_13 extends ByteCharset
"8859_13",
"cp921",
"921"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_13
diff --git a/gnu/java/nio/charset/ISO_8859_15.java b/gnu/java/nio/charset/ISO_8859_15.java
index 973fe1c94..df2265ac5 100644
--- a/gnu/java/nio/charset/ISO_8859_15.java
+++ b/gnu/java/nio/charset/ISO_8859_15.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-15, ISO Latin-9 char set.
*/
-public class ISO_8859_15 extends ByteCharset
+public final class ISO_8859_15 extends ByteCharset
{
/**
@@ -103,8 +103,7 @@ public class ISO_8859_15 extends ByteCharset
"cp923",
"923",
"windows-28605"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_15
diff --git a/gnu/java/nio/charset/ISO_8859_2.java b/gnu/java/nio/charset/ISO_8859_2.java
index 2de96df9b..dbe2b4dbf 100644
--- a/gnu/java/nio/charset/ISO_8859_2.java
+++ b/gnu/java/nio/charset/ISO_8859_2.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-2, ISO Latin-2 char set.
*/
-public class ISO_8859_2 extends ByteCharset
+public final class ISO_8859_2 extends ByteCharset
{
/**
@@ -102,8 +102,7 @@ public class ISO_8859_2 extends ByteCharset
"cp912",
"912",
"windows-28592"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_2
diff --git a/gnu/java/nio/charset/ISO_8859_3.java b/gnu/java/nio/charset/ISO_8859_3.java
index 6e718719a..567379e7d 100644
--- a/gnu/java/nio/charset/ISO_8859_3.java
+++ b/gnu/java/nio/charset/ISO_8859_3.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-3, ISO Latin-3 char set.
*/
-public class ISO_8859_3 extends ByteCharset
+public final class ISO_8859_3 extends ByteCharset
{
/**
@@ -101,8 +101,7 @@ public class ISO_8859_3 extends ByteCharset
"cp913",
"913",
"windows-28593"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_3
diff --git a/gnu/java/nio/charset/ISO_8859_4.java b/gnu/java/nio/charset/ISO_8859_4.java
index 96dc46754..ca062278a 100644
--- a/gnu/java/nio/charset/ISO_8859_4.java
+++ b/gnu/java/nio/charset/ISO_8859_4.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-4, ISO Latin-4 char set.
*/
-public class ISO_8859_4 extends ByteCharset
+public final class ISO_8859_4 extends ByteCharset
{
/**
@@ -102,8 +102,7 @@ public class ISO_8859_4 extends ByteCharset
"cp914",
"914",
"windows-28594"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_4
diff --git a/gnu/java/nio/charset/ISO_8859_5.java b/gnu/java/nio/charset/ISO_8859_5.java
index ad208729c..70496ce49 100644
--- a/gnu/java/nio/charset/ISO_8859_5.java
+++ b/gnu/java/nio/charset/ISO_8859_5.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-5, ISO cyrillic char set.
*/
-public class ISO_8859_5 extends ByteCharset
+public final class ISO_8859_5 extends ByteCharset
{
/**
@@ -100,8 +100,7 @@ public class ISO_8859_5 extends ByteCharset
"cp915",
"915",
"windows-28595"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_5
diff --git a/gnu/java/nio/charset/ISO_8859_6.java b/gnu/java/nio/charset/ISO_8859_6.java
index 5600e7923..dc7a9bef8 100644
--- a/gnu/java/nio/charset/ISO_8859_6.java
+++ b/gnu/java/nio/charset/ISO_8859_6.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-6, ISO Arabic char set.
*/
-public class ISO_8859_6 extends ByteCharset
+public final class ISO_8859_6 extends ByteCharset
{
/**
@@ -104,8 +104,7 @@ public class ISO_8859_6 extends ByteCharset
"windows-28596",
"ISO-8859-6-I",
"ISO-8859-6-E"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_6
diff --git a/gnu/java/nio/charset/ISO_8859_7.java b/gnu/java/nio/charset/ISO_8859_7.java
index 9262a6077..195f16094 100644
--- a/gnu/java/nio/charset/ISO_8859_7.java
+++ b/gnu/java/nio/charset/ISO_8859_7.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-7, ISO Latin/Greek char set.
*/
-public class ISO_8859_7 extends ByteCharset
+public final class ISO_8859_7 extends ByteCharset
{
/**
@@ -103,8 +103,7 @@ public class ISO_8859_7 extends ByteCharset
"cp813",
"813",
"windows-28597"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_7
diff --git a/gnu/java/nio/charset/ISO_8859_8.java b/gnu/java/nio/charset/ISO_8859_8.java
index 96fb0f48b..b58030f17 100644
--- a/gnu/java/nio/charset/ISO_8859_8.java
+++ b/gnu/java/nio/charset/ISO_8859_8.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-8, ISO Latin/Hebrew char set.
*/
-public class ISO_8859_8 extends ByteCharset
+public final class ISO_8859_8 extends ByteCharset
{
/**
@@ -102,8 +102,7 @@ public class ISO_8859_8 extends ByteCharset
"cp916",
"916",
"windows-28598"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_8
diff --git a/gnu/java/nio/charset/ISO_8859_9.java b/gnu/java/nio/charset/ISO_8859_9.java
index 28be34cf8..83fb5a222 100644
--- a/gnu/java/nio/charset/ISO_8859_9.java
+++ b/gnu/java/nio/charset/ISO_8859_9.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for ISO-8859-9, ISO Latin-5 char set.
*/
-public class ISO_8859_9 extends ByteCharset
+public final class ISO_8859_9 extends ByteCharset
{
/**
@@ -102,8 +102,7 @@ public class ISO_8859_9 extends ByteCharset
"920",
"windows-28599",
"ECMA-128"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class ISO_8859_9
diff --git a/gnu/java/nio/charset/KOI_8.java b/gnu/java/nio/charset/KOI_8.java
index c67065607..20eb8b198 100644
--- a/gnu/java/nio/charset/KOI_8.java
+++ b/gnu/java/nio/charset/KOI_8.java
@@ -41,7 +41,7 @@ package gnu.java.nio.charset;
/**
* Encoding table for the KOI8 cyrillic char set.
*/
-public class KOI_8 extends ByteCharset
+public final class KOI_8 extends ByteCharset
{
/**
@@ -94,8 +94,7 @@ public class KOI_8 extends ByteCharset
"koi8r",
"koi-8-r",
"koi"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class KOI_8
diff --git a/gnu/java/nio/charset/MS874.java b/gnu/java/nio/charset/MS874.java
index b16e53f42..f7cf81a25 100644
--- a/gnu/java/nio/charset/MS874.java
+++ b/gnu/java/nio/charset/MS874.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MS874 extends ByteCharset
+public final class MS874 extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MS874 extends ByteCharset
public MS874()
{
- super("MS874", new String[] {
- });
- lookupTable = lookup;
+ super("MS874", new String[] {}, lookup);
}
} // class MS874
diff --git a/gnu/java/nio/charset/MacCentralEurope.java b/gnu/java/nio/charset/MacCentralEurope.java
index 5496db2b5..ce0854365 100644
--- a/gnu/java/nio/charset/MacCentralEurope.java
+++ b/gnu/java/nio/charset/MacCentralEurope.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacCentralEurope extends ByteCharset
+public final class MacCentralEurope extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacCentralEurope extends ByteCharset
public MacCentralEurope()
{
- super("MacCentralEurope", new String[] {
- });
- lookupTable = lookup;
+ super("MacCentralEurope", new String[] {}, lookup);
}
} // class MacCentralEurope
diff --git a/gnu/java/nio/charset/MacCroatian.java b/gnu/java/nio/charset/MacCroatian.java
index f71ac5199..3bb19f5e2 100644
--- a/gnu/java/nio/charset/MacCroatian.java
+++ b/gnu/java/nio/charset/MacCroatian.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacCroatian extends ByteCharset
+public final class MacCroatian extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacCroatian extends ByteCharset
public MacCroatian()
{
- super("MacCroatian", new String[] {
- });
- lookupTable = lookup;
+ super("MacCroatian", new String[] {}, lookup);
}
} // class MacCroatian
diff --git a/gnu/java/nio/charset/MacCyrillic.java b/gnu/java/nio/charset/MacCyrillic.java
index f152f6b1c..b1984e57a 100644
--- a/gnu/java/nio/charset/MacCyrillic.java
+++ b/gnu/java/nio/charset/MacCyrillic.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacCyrillic extends ByteCharset
+public final class MacCyrillic extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacCyrillic extends ByteCharset
public MacCyrillic()
{
- super("MacCyrillic", new String[] {
- });
- lookupTable = lookup;
+ super("MacCyrillic", new String[] {}, lookup);
}
} // class MacCyrillic
diff --git a/gnu/java/nio/charset/MacDingbat.java b/gnu/java/nio/charset/MacDingbat.java
index 84102d56f..ad2f1c851 100644
--- a/gnu/java/nio/charset/MacDingbat.java
+++ b/gnu/java/nio/charset/MacDingbat.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacDingbat extends ByteCharset
+public final class MacDingbat extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacDingbat extends ByteCharset
public MacDingbat()
{
- super("MacDingbat", new String[] {
- });
- lookupTable = lookup;
+ super("MacDingbat", new String[] {}, lookup);
}
} // class MacDingbat
diff --git a/gnu/java/nio/charset/MacGreek.java b/gnu/java/nio/charset/MacGreek.java
index 07624d59e..6d1522874 100644
--- a/gnu/java/nio/charset/MacGreek.java
+++ b/gnu/java/nio/charset/MacGreek.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacGreek extends ByteCharset
+public final class MacGreek extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacGreek extends ByteCharset
public MacGreek()
{
- super("MacGreek", new String[] {
- });
- lookupTable = lookup;
+ super("MacGreek", new String[] {}, lookup);
}
} // class MacGreek
diff --git a/gnu/java/nio/charset/MacIceland.java b/gnu/java/nio/charset/MacIceland.java
index 7918e0266..a8eb7036c 100644
--- a/gnu/java/nio/charset/MacIceland.java
+++ b/gnu/java/nio/charset/MacIceland.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacIceland extends ByteCharset
+public final class MacIceland extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacIceland extends ByteCharset
public MacIceland()
{
- super("MacIceland", new String[] {
- });
- lookupTable = lookup;
+ super("MacIceland", new String[] {}, lookup);
}
} // class MacIceland
diff --git a/gnu/java/nio/charset/MacRoman.java b/gnu/java/nio/charset/MacRoman.java
index b413caf2b..72738a2aa 100644
--- a/gnu/java/nio/charset/MacRoman.java
+++ b/gnu/java/nio/charset/MacRoman.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacRoman extends ByteCharset
+public final class MacRoman extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacRoman extends ByteCharset
public MacRoman()
{
- super("MacRoman", new String[] {
- });
- lookupTable = lookup;
+ super("MacRoman", new String[] {}, lookup);
}
} // class MacRoman
diff --git a/gnu/java/nio/charset/MacRomania.java b/gnu/java/nio/charset/MacRomania.java
index d1779a40e..e05e94025 100644
--- a/gnu/java/nio/charset/MacRomania.java
+++ b/gnu/java/nio/charset/MacRomania.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacRomania extends ByteCharset
+public final class MacRomania extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacRomania extends ByteCharset
public MacRomania()
{
- super("MacRomania", new String[] {
- });
- lookupTable = lookup;
+ super("MacRomania", new String[] {}, lookup);
}
} // class MacRomania
diff --git a/gnu/java/nio/charset/MacSymbol.java b/gnu/java/nio/charset/MacSymbol.java
index 869de1947..9878efd89 100644
--- a/gnu/java/nio/charset/MacSymbol.java
+++ b/gnu/java/nio/charset/MacSymbol.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacSymbol extends ByteCharset
+public final class MacSymbol extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacSymbol extends ByteCharset
public MacSymbol()
{
- super("MacSymbol", new String[] {
- });
- lookupTable = lookup;
+ super("MacSymbol", new String[] {}, lookup);
}
} // class MacSymbol
diff --git a/gnu/java/nio/charset/MacThai.java b/gnu/java/nio/charset/MacThai.java
index 498b9e6bb..daed75630 100644
--- a/gnu/java/nio/charset/MacThai.java
+++ b/gnu/java/nio/charset/MacThai.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacThai extends ByteCharset
+public final class MacThai extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacThai extends ByteCharset
public MacThai()
{
- super("MacThai", new String[] {
- });
- lookupTable = lookup;
+ super("MacThai", new String[] {}, lookup);
}
} // class MacThai
diff --git a/gnu/java/nio/charset/MacTurkish.java b/gnu/java/nio/charset/MacTurkish.java
index 68ea27b8c..b623ee39a 100644
--- a/gnu/java/nio/charset/MacTurkish.java
+++ b/gnu/java/nio/charset/MacTurkish.java
@@ -37,7 +37,7 @@ exception statement from your version. */
package gnu.java.nio.charset;
-public class MacTurkish extends ByteCharset
+public final class MacTurkish extends ByteCharset
{
/**
@@ -81,9 +81,7 @@ public class MacTurkish extends ByteCharset
public MacTurkish()
{
- super("MacTurkish", new String[] {
- });
- lookupTable = lookup;
+ super("MacTurkish", new String[] {}, lookup);
}
} // class MacTurkish
diff --git a/gnu/java/nio/charset/Provider.java b/gnu/java/nio/charset/Provider.java
index b56e5a90e..d3b71a612 100644
--- a/gnu/java/nio/charset/Provider.java
+++ b/gnu/java/nio/charset/Provider.java
@@ -67,14 +67,14 @@ public final class Provider extends CharsetProvider
* are all lower-case to allow case-insensitive retrieval of
* Charset instances.
*/
- private final HashMap canonicalNames;
+ private final HashMap<String, String> canonicalNames;
/**
* Map from lower-case canonical name to Charset.
* TODO: We may want to use soft references. We would then need to keep
* track of the class name to regenerate the object.
*/
- private final HashMap charsets;
+ private final HashMap<String, Charset> charsets;
/**
* We don't load all available charsets at the start
@@ -85,8 +85,8 @@ public final class Provider extends CharsetProvider
Provider ()
{
extendedLoaded = false;
- canonicalNames = new HashMap ();
- charsets = new HashMap ();
+ canonicalNames = new HashMap<String,String> ();
+ charsets = new HashMap<String,Charset> ();
// US-ASCII aka ISO646-US
addCharset (new US_ASCII ());
@@ -203,7 +203,7 @@ public final class Provider extends CharsetProvider
extendedLoaded = true;
}
- public Iterator charsets ()
+ public Iterator<Charset> charsets ()
{
loadExtended();
return Collections.unmodifiableCollection (charsets.values ())
@@ -250,7 +250,7 @@ public final class Provider extends CharsetProvider
*/
canonicalNames.put(canonicalName, canonicalName);
- for (Iterator i = cs.aliases ().iterator (); i.hasNext (); )
+ for (Iterator<String> i = cs.aliases ().iterator (); i.hasNext (); )
canonicalNames.put (((String) i.next()).toLowerCase(), canonicalName);
}
@@ -258,10 +258,10 @@ public final class Provider extends CharsetProvider
{
// The default provider is safe to instantiate.
if (singleton == null)
- singleton = (Provider) AccessController.doPrivileged
- (new PrivilegedAction()
+ singleton = AccessController.doPrivileged
+ (new PrivilegedAction<Provider>()
{
- public Object run()
+ public Provider run()
{
return new Provider();
}
diff --git a/gnu/java/nio/charset/US_ASCII.java b/gnu/java/nio/charset/US_ASCII.java
index 8888416be..b09c43e61 100644
--- a/gnu/java/nio/charset/US_ASCII.java
+++ b/gnu/java/nio/charset/US_ASCII.java
@@ -48,6 +48,7 @@ import java.nio.charset.CoderResult;
* US-ASCII charset.
*
* @author Jesse Rosenstock
+ * @modified Ian Rogers
*/
final class US_ASCII extends Charset
{
@@ -95,6 +96,19 @@ final class US_ASCII extends Charset
private static final class Decoder extends CharsetDecoder
{
+ /** Helper to decode loops */
+ private static final ByteDecodeLoopHelper helper = new ByteDecodeLoopHelper()
+ {
+ protected boolean isMappable(byte b)
+ {
+ return b >= 0;
+ }
+ protected char mapToChar(byte b)
+ {
+ return (char)b;
+ }
+ };
+
// Package-private to avoid a trampoline constructor.
Decoder (Charset cs)
{
@@ -103,31 +117,24 @@ final class US_ASCII extends Charset
protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- byte b = in.get ();
-
- if (b < 0)
- {
- in.position (in.position () - 1);
- return CoderResult.malformedForLength (1);
- }
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((char) b);
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.decodeLoop(in, out);
}
}
private static final class Encoder extends CharsetEncoder
{
+ /** Helper to encode loops */
+ private static final ByteEncodeLoopHelper helper = new ByteEncodeLoopHelper()
+ {
+ protected boolean isMappable(char c)
+ {
+ return c <= 0x7f;
+ }
+ protected byte mapToByte(char c)
+ {
+ return (byte)c;
+ }
+ };
// Package-private to avoid a trampoline constructor.
Encoder (Charset cs)
{
@@ -149,26 +156,7 @@ final class US_ASCII extends Charset
protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- char c = in.get ();
-
- if (c > 0x7f)
- {
- in.position (in.position () - 1);
- return CoderResult.unmappableForLength (1);
- }
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((byte) c);
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.encodeLoop(in, out);
}
}
}
diff --git a/gnu/java/nio/charset/Windows1250.java b/gnu/java/nio/charset/Windows1250.java
index 9d7ab8edd..f8fc90ae2 100644
--- a/gnu/java/nio/charset/Windows1250.java
+++ b/gnu/java/nio/charset/Windows1250.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1250-Latin-1,
* aka cp1250 or Windows-1250 or whatever.
*/
-public class Windows1250 extends ByteCharset
+public final class Windows1250 extends ByteCharset
{
/**
@@ -95,8 +95,7 @@ public class Windows1250 extends ByteCharset
"cp_1250",
"windows1250",
"windows_1250"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1250
diff --git a/gnu/java/nio/charset/Windows1251.java b/gnu/java/nio/charset/Windows1251.java
index bf3227e87..51f289e2a 100644
--- a/gnu/java/nio/charset/Windows1251.java
+++ b/gnu/java/nio/charset/Windows1251.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1251 Cyrillic char set.
* aka cp1251 or Windows-1251 or whatever.
*/
-public class Windows1251 extends ByteCharset
+public final class Windows1251 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1251 extends ByteCharset
"cp_1251",
"windows1251",
"windows_1251"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1251
diff --git a/gnu/java/nio/charset/Windows1252.java b/gnu/java/nio/charset/Windows1252.java
index 9391c87d4..03d15802c 100644
--- a/gnu/java/nio/charset/Windows1252.java
+++ b/gnu/java/nio/charset/Windows1252.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1252-Latin-1,
* aka cp1252 or Windows-1252 or whatever.
*/
-public class Windows1252 extends ByteCharset
+public final class Windows1252 extends ByteCharset
{
/**
@@ -92,8 +92,7 @@ public class Windows1252 extends ByteCharset
"windows-1252",
"cp1252",
"cp-1252"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1252
diff --git a/gnu/java/nio/charset/Windows1253.java b/gnu/java/nio/charset/Windows1253.java
index 02150b4af..9e5b1f769 100644
--- a/gnu/java/nio/charset/Windows1253.java
+++ b/gnu/java/nio/charset/Windows1253.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1253 Greek char set.
* aka cp1253 or Windows-1253 or whatever.
*/
-public class Windows1253 extends ByteCharset
+public final class Windows1253 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1253 extends ByteCharset
"cp_1253",
"windows1253",
"windows_1253"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1253
diff --git a/gnu/java/nio/charset/Windows1254.java b/gnu/java/nio/charset/Windows1254.java
index 7cdad3c46..9025421b3 100644
--- a/gnu/java/nio/charset/Windows1254.java
+++ b/gnu/java/nio/charset/Windows1254.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1254 Turkish char set.
* aka cp1254 or Windows-1254 or whatever.
*/
-public class Windows1254 extends ByteCharset
+public final class Windows1254 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1254 extends ByteCharset
"cp_1254",
"windows1254",
"windows_1254"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1254
diff --git a/gnu/java/nio/charset/Windows1255.java b/gnu/java/nio/charset/Windows1255.java
index b706d1930..61787d184 100644
--- a/gnu/java/nio/charset/Windows1255.java
+++ b/gnu/java/nio/charset/Windows1255.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1255 Hebrew char set.
* aka cp1255 or Windows-1255 or whatever.
*/
-public class Windows1255 extends ByteCharset
+public final class Windows1255 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1255 extends ByteCharset
"cp_1255",
"windows1255",
"windows_1255"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1255
diff --git a/gnu/java/nio/charset/Windows1256.java b/gnu/java/nio/charset/Windows1256.java
index 6924420e1..cf88c21b4 100644
--- a/gnu/java/nio/charset/Windows1256.java
+++ b/gnu/java/nio/charset/Windows1256.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1256 Arabic char set.
* aka cp1256 or Windows-1256 or whatever.
*/
-public class Windows1256 extends ByteCharset
+public final class Windows1256 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1256 extends ByteCharset
"cp_1256",
"windows1256",
"windows_1256"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1256
diff --git a/gnu/java/nio/charset/Windows1257.java b/gnu/java/nio/charset/Windows1257.java
index 2f95d64ac..2d281d9cd 100644
--- a/gnu/java/nio/charset/Windows1257.java
+++ b/gnu/java/nio/charset/Windows1257.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1257 Baltic char set.
* aka cp1257 or Windows-1257 or whatever.
*/
-public class Windows1257 extends ByteCharset
+public final class Windows1257 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1257 extends ByteCharset
"cp_1257",
"windows1257",
"windows_1257"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1257
diff --git a/gnu/java/nio/charset/Windows1258.java b/gnu/java/nio/charset/Windows1258.java
index 7d653b497..63ef37f1a 100644
--- a/gnu/java/nio/charset/Windows1258.java
+++ b/gnu/java/nio/charset/Windows1258.java
@@ -42,7 +42,7 @@ package gnu.java.nio.charset;
* Encoding table for Windows-1258 Arabic char set.
* aka cp1258 or Windows-1258 or whatever.
*/
-public class Windows1258 extends ByteCharset
+public final class Windows1258 extends ByteCharset
{
/**
@@ -93,8 +93,7 @@ public class Windows1258 extends ByteCharset
"cp_1258",
"windows1258",
"windows_1258"
- });
- lookupTable = lookup;
+ }, lookup);
}
} // class Windows1258