# HG changeset patch
# User Jaroslav Tulach
# Date 1380891737 -7200
# Node ID 802e5d2da9f69e11593d6bd5dbf41ba5df05ead5
# Parent 44015f05c91b5a9463c34ddcd98d56d57684df35
Charset can be compiled now
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/io/OutputStreamWriter.java
--- a/rt/emul/compact/src/main/java/java/io/OutputStreamWriter.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/io/OutputStreamWriter.java Fri Oct 04 15:02:17 2013 +0200
@@ -25,6 +25,8 @@
package java.io;
+import java.nio.charset.Charset;
+
/**
* An OutputStreamWriter is a bridge from character streams to byte streams:
* Characters written to it are encoded into bytes using a specified {@link
@@ -116,12 +118,9 @@
* @since 1.4
* @spec JSR-51
*/
-// public OutputStreamWriter(OutputStream out, Charset cs) {
-// super(out);
-// if (cs == null)
-// throw new NullPointerException("charset");
-// se = StreamEncoder.forOutputStreamWriter(out, this, cs);
-// }
+ public OutputStreamWriter(OutputStream out, Charset cs) {
+ this(out);
+ }
/**
* Creates an OutputStreamWriter that uses the given charset encoder.
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/io/PrintStream.java
--- a/rt/emul/compact/src/main/java/java/io/PrintStream.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/io/PrintStream.java Fri Oct 04 15:02:17 2013 +0200
@@ -25,6 +25,7 @@
package java.io;
+import java.nio.charset.Charset;
import java.util.Arrays;
@@ -88,9 +89,6 @@
static final class Formatter {
}
- static final class Charset {
- }
-
static Charset toCharset(String ch) throws UnsupportedEncodingException {
if (!"UTF-8".equals(ch)) {
throw new UnsupportedEncodingException();
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/io/PrintWriter.java
--- a/rt/emul/compact/src/main/java/java/io/PrintWriter.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/io/PrintWriter.java Fri Oct 04 15:02:17 2013 +0200
@@ -25,10 +25,9 @@
package java.io;
-import java.io.PrintStream.Charset;
import java.io.PrintStream.Formatter;
+import java.nio.charset.Charset;
import java.util.Arrays;
-import java.util.Objects;
/**
* Prints formatted representations of objects to a text-output stream. This
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/nio/charset/Charset.java
--- a/rt/emul/compact/src/main/java/java/nio/charset/Charset.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/nio/charset/Charset.java Fri Oct 04 15:02:17 2013 +0200
@@ -25,27 +25,16 @@
package java.nio.charset;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.spi.CharsetProvider;
-import java.security.AccessController;
-import java.security.AccessControlException;
-import java.security.PrivilegedAction;
+//import java.nio.ByteBuffer;
+//import java.nio.CharBuffer;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
-import java.util.NoSuchElementException;
import java.util.Set;
-import java.util.ServiceLoader;
-import java.util.ServiceConfigurationError;
import java.util.SortedMap;
import java.util.TreeMap;
-import sun.misc.ASCIICaseInsensitiveComparator;
-import sun.nio.cs.StandardCharsets;
-import sun.nio.cs.ThreadLocalCoders;
-import sun.security.action.GetPropertyAction;
/**
@@ -281,17 +270,6 @@
private static volatile String bugLevel = null;
- static boolean atBugLevel(String bl) { // package-private
- String level = bugLevel;
- if (level == null) {
- if (!sun.misc.VM.isBooted())
- return false;
- bugLevel = level = AccessController.doPrivileged(
- new GetPropertyAction("sun.nio.cs.bugLevel", ""));
- }
- return level.equals(bl);
- }
-
/**
* Checks that the given string is a legal charset name.
*
@@ -303,10 +281,8 @@
*/
private static void checkName(String s) {
int n = s.length();
- if (!atBugLevel("1.4")) {
if (n == 0)
throw new IllegalCharsetNameException(s);
- }
for (int i = 0; i < n; i++) {
char c = s.charAt(i);
if (c >= 'A' && c <= 'Z') continue;
@@ -321,9 +297,6 @@
}
}
- /* The standard set of charsets */
- private static CharsetProvider standardProvider = new StandardCharsets();
-
// Cache of the most-recently-returned charsets,
// along with the names that were used to find them
//
@@ -340,126 +313,23 @@
// thrown. Should be invoked with full privileges.
//
private static Iterator providers() {
- return new Iterator() {
-
- ClassLoader cl = ClassLoader.getSystemClassLoader();
- ServiceLoader sl =
- ServiceLoader.load(CharsetProvider.class, cl);
- Iterator i = sl.iterator();
-
- Object next = null;
-
- private boolean getNext() {
- while (next == null) {
- try {
- if (!i.hasNext())
- return false;
- next = i.next();
- } catch (ServiceConfigurationError sce) {
- if (sce.getCause() instanceof SecurityException) {
- // Ignore security exceptions
- continue;
- }
- throw sce;
- }
- }
- return true;
- }
-
- public boolean hasNext() {
- return getNext();
- }
-
- public Object next() {
- if (!getNext())
- throw new NoSuchElementException();
- Object n = next;
- next = null;
- return n;
- }
-
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- };
+ return Collections.emptyIterator();
}
// Thread-local gate to prevent recursive provider lookups
private static ThreadLocal gate = new ThreadLocal();
private static Charset lookupViaProviders(final String charsetName) {
-
- // The runtime startup sequence looks up standard charsets as a
- // consequence of the VM's invocation of System.initializeSystemClass
- // in order to, e.g., set system properties and encode filenames. At
- // that point the application class loader has not been initialized,
- // however, so we can't look for providers because doing so will cause
- // that loader to be prematurely initialized with incomplete
- // information.
- //
- if (!sun.misc.VM.isBooted())
- return null;
-
- if (gate.get() != null)
- // Avoid recursive provider lookups
- return null;
- try {
- gate.set(gate);
-
- return AccessController.doPrivileged(
- new PrivilegedAction() {
- public Charset run() {
- for (Iterator i = providers(); i.hasNext();) {
- CharsetProvider cp = (CharsetProvider)i.next();
- Charset cs = cp.charsetForName(charsetName);
- if (cs != null)
- return cs;
- }
- return null;
- }
- });
-
- } finally {
- gate.set(null);
- }
+ return null;
}
/* The extended set of charsets */
private static Object extendedProviderLock = new Object();
private static boolean extendedProviderProbed = false;
- private static CharsetProvider extendedProvider = null;
- private static void probeExtendedProvider() {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- try {
- Class epc
- = Class.forName("sun.nio.cs.ext.ExtendedCharsets");
- extendedProvider = (CharsetProvider)epc.newInstance();
- } catch (ClassNotFoundException x) {
- // Extended charsets not available
- // (charsets.jar not present)
- } catch (InstantiationException x) {
- throw new Error(x);
- } catch (IllegalAccessException x) {
- throw new Error(x);
- }
- return null;
- }
- });
- }
private static Charset lookupExtendedCharset(String charsetName) {
- CharsetProvider ecp = null;
- synchronized (extendedProviderLock) {
- if (!extendedProviderProbed) {
- probeExtendedProvider();
- extendedProviderProbed = true;
- }
- ecp = extendedProvider;
- }
- return (ecp != null) ? ecp.charsetForName(charsetName) : null;
+ return null;
}
private static Charset lookup(String charsetName) {
@@ -483,15 +353,6 @@
return (Charset)a[1];
}
- Charset cs;
- if ((cs = standardProvider.charsetForName(charsetName)) != null ||
- (cs = lookupExtendedCharset(charsetName)) != null ||
- (cs = lookupViaProviders(charsetName)) != null)
- {
- cache(charsetName, cs);
- return cs;
- }
-
/* Only need to check the name if we didn't find a charset for it */
checkName(charsetName);
return null;
@@ -581,20 +442,9 @@
* to charset objects
*/
public static SortedMap availableCharsets() {
- return AccessController.doPrivileged(
- new PrivilegedAction>() {
- public SortedMap run() {
- TreeMap m =
- new TreeMap(
- ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
- put(standardProvider.charsets(), m);
- for (Iterator i = providers(); i.hasNext();) {
- CharsetProvider cp = (CharsetProvider)i.next();
- put(cp.charsets(), m);
- }
- return Collections.unmodifiableSortedMap(m);
- }
- });
+ TreeMap tm = new TreeMap();
+ tm.put("UTF-8", Charset.defaultCharset());
+ return tm;
}
private static volatile Charset defaultCharset;
@@ -612,15 +462,7 @@
*/
public static Charset defaultCharset() {
if (defaultCharset == null) {
- synchronized (Charset.class) {
- String csn = AccessController.doPrivileged(
- new GetPropertyAction("file.encoding"));
- Charset cs = lookup(csn);
- if (cs != null)
- defaultCharset = cs;
- else
- defaultCharset = forName("UTF-8");
- }
+ defaultCharset = forName("UTF-8");
}
return defaultCharset;
}
@@ -805,16 +647,16 @@
*
* @return A char buffer containing the decoded characters
*/
- public final CharBuffer decode(ByteBuffer bb) {
- try {
- return ThreadLocalCoders.decoderFor(this)
- .onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE)
- .decode(bb);
- } catch (CharacterCodingException x) {
- throw new Error(x); // Can't happen
- }
- }
+// public final CharBuffer decode(ByteBuffer bb) {
+// try {
+// return ThreadLocalCoders.decoderFor(this)
+// .onMalformedInput(CodingErrorAction.REPLACE)
+// .onUnmappableCharacter(CodingErrorAction.REPLACE)
+// .decode(bb);
+// } catch (CharacterCodingException x) {
+// throw new Error(x); // Can't happen
+// }
+// }
/**
* Convenience method that encodes Unicode characters into bytes in this
@@ -841,16 +683,16 @@
*
* @return A byte buffer containing the encoded characters
*/
- public final ByteBuffer encode(CharBuffer cb) {
- try {
- return ThreadLocalCoders.encoderFor(this)
- .onMalformedInput(CodingErrorAction.REPLACE)
- .onUnmappableCharacter(CodingErrorAction.REPLACE)
- .encode(cb);
- } catch (CharacterCodingException x) {
- throw new Error(x); // Can't happen
- }
- }
+// public final ByteBuffer encode(CharBuffer cb) {
+// try {
+// return ThreadLocalCoders.encoderFor(this)
+// .onMalformedInput(CodingErrorAction.REPLACE)
+// .onUnmappableCharacter(CodingErrorAction.REPLACE)
+// .encode(cb);
+// } catch (CharacterCodingException x) {
+// throw new Error(x); // Can't happen
+// }
+// }
/**
* Convenience method that encodes a string into bytes in this charset.
@@ -865,9 +707,9 @@
*
* @return A byte buffer containing the encoded characters
*/
- public final ByteBuffer encode(String str) {
- return encode(CharBuffer.wrap(str));
- }
+// public final ByteBuffer encode(String str) {
+// return encode(CharBuffer.wrap(str));
+// }
/**
* Compares this charset to another.
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java
--- a/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/nio/charset/CharsetDecoder.java Fri Oct 04 15:02:17 2013 +0200
@@ -27,13 +27,13 @@
package java.nio.charset;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
+//import java.nio.Buffer;
+//import java.nio.ByteBuffer;
+//import java.nio.CharBuffer;
+//import java.nio.BufferOverflowException;
+//import java.nio.BufferUnderflowException;
import java.lang.ref.WeakReference;
-import java.nio.charset.CoderMalfunctionError; // javadoc
+//import java.nio.charset.CoderMalfunctionError; // javadoc
/**
@@ -140,10 +140,10 @@
private final float maxCharsPerByte;
private String replacement;
- private CodingErrorAction malformedInputAction
- = CodingErrorAction.REPORT;
- private CodingErrorAction unmappableCharacterAction
- = CodingErrorAction.REPORT;
+// private CodingErrorAction malformedInputAction
+// = CodingErrorAction.REPORT;
+// private CodingErrorAction unmappableCharacterAction
+// = CodingErrorAction.REPORT;
// Internal states
//
@@ -191,12 +191,10 @@
if (maxCharsPerByte <= 0.0f)
throw new IllegalArgumentException("Non-positive "
+ "maxCharsPerByte");
- if (!Charset.atBugLevel("1.4")) {
- if (averageCharsPerByte > maxCharsPerByte)
- throw new IllegalArgumentException("averageCharsPerByte"
- + " exceeds "
- + "maxCharsPerByte");
- }
+ if (averageCharsPerByte > maxCharsPerByte)
+ throw new IllegalArgumentException("averageCharsPerByte"
+ + " exceeds "
+ + "maxCharsPerByte");
this.replacement = replacement;
this.averageCharsPerByte = averageCharsPerByte;
this.maxCharsPerByte = maxCharsPerByte;
@@ -346,9 +344,9 @@
*
* @return The current malformed-input action, which is never null
*/
- public CodingErrorAction malformedInputAction() {
- return malformedInputAction;
- }
+// public CodingErrorAction malformedInputAction() {
+// return malformedInputAction;
+// }
/**
* Changes this decoder's action for malformed-input errors.
@@ -363,13 +361,13 @@
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
- public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- malformedInputAction = newAction;
- implOnMalformedInput(newAction);
- return this;
- }
+// public final CharsetDecoder onMalformedInput(CodingErrorAction newAction) {
+// if (newAction == null)
+// throw new IllegalArgumentException("Null action");
+// malformedInputAction = newAction;
+// implOnMalformedInput(newAction);
+// return this;
+// }
/**
* Reports a change to this decoder's malformed-input action.
@@ -378,7 +376,7 @@
* should be overridden by decoders that require notification of changes to
* the malformed-input action.
*/
- protected void implOnMalformedInput(CodingErrorAction newAction) { }
+// protected void implOnMalformedInput(CodingErrorAction newAction) { }
/**
* Returns this decoder's current action for unmappable-character errors.
@@ -387,9 +385,9 @@
* @return The current unmappable-character action, which is never
* null
*/
- public CodingErrorAction unmappableCharacterAction() {
- return unmappableCharacterAction;
- }
+// public CodingErrorAction unmappableCharacterAction() {
+// return unmappableCharacterAction;
+// }
/**
* Changes this decoder's action for unmappable-character errors.
@@ -404,15 +402,15 @@
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
- public final CharsetDecoder onUnmappableCharacter(CodingErrorAction
- newAction)
- {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- unmappableCharacterAction = newAction;
- implOnUnmappableCharacter(newAction);
- return this;
- }
+// public final CharsetDecoder onUnmappableCharacter(CodingErrorAction
+// newAction)
+// {
+// if (newAction == null)
+// throw new IllegalArgumentException("Null action");
+// unmappableCharacterAction = newAction;
+// implOnUnmappableCharacter(newAction);
+// return this;
+// }
/**
* Reports a change to this decoder's unmappable-character action.
@@ -421,7 +419,7 @@
* should be overridden by decoders that require notification of changes to
* the unmappable-character action.
*/
- protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
+// protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
/**
* Returns the average number of characters that will be produced for each
@@ -545,66 +543,66 @@
* If an invocation of the decodeLoop method threw
* an unexpected exception
*/
- public final CoderResult decode(ByteBuffer in, CharBuffer out,
- boolean endOfInput)
- {
- int newState = endOfInput ? ST_END : ST_CODING;
- if ((state != ST_RESET) && (state != ST_CODING)
- && !(endOfInput && (state == ST_END)))
- throwIllegalStateException(state, newState);
- state = newState;
-
- for (;;) {
-
- CoderResult cr;
- try {
- cr = decodeLoop(in, out);
- } catch (BufferUnderflowException x) {
- throw new CoderMalfunctionError(x);
- } catch (BufferOverflowException x) {
- throw new CoderMalfunctionError(x);
- }
-
- if (cr.isOverflow())
- return cr;
-
- if (cr.isUnderflow()) {
- if (endOfInput && in.hasRemaining()) {
- cr = CoderResult.malformedForLength(in.remaining());
- // Fall through to malformed-input case
- } else {
- return cr;
- }
- }
-
- CodingErrorAction action = null;
- if (cr.isMalformed())
- action = malformedInputAction;
- else if (cr.isUnmappable())
- action = unmappableCharacterAction;
- else
- assert false : cr.toString();
-
- if (action == CodingErrorAction.REPORT)
- return cr;
-
- if (action == CodingErrorAction.REPLACE) {
- if (out.remaining() < replacement.length())
- return CoderResult.OVERFLOW;
- out.put(replacement);
- }
-
- if ((action == CodingErrorAction.IGNORE)
- || (action == CodingErrorAction.REPLACE)) {
- // Skip erroneous input either way
- in.position(in.position() + cr.length());
- continue;
- }
-
- assert false;
- }
-
- }
+// public final CoderResult decode(ByteBuffer in, CharBuffer out,
+// boolean endOfInput)
+// {
+// int newState = endOfInput ? ST_END : ST_CODING;
+// if ((state != ST_RESET) && (state != ST_CODING)
+// && !(endOfInput && (state == ST_END)))
+// throwIllegalStateException(state, newState);
+// state = newState;
+//
+// for (;;) {
+//
+// CoderResult cr;
+// try {
+// cr = decodeLoop(in, out);
+// } catch (BufferUnderflowException x) {
+// throw new CoderMalfunctionError(x);
+// } catch (BufferOverflowException x) {
+// throw new CoderMalfunctionError(x);
+// }
+//
+// if (cr.isOverflow())
+// return cr;
+//
+// if (cr.isUnderflow()) {
+// if (endOfInput && in.hasRemaining()) {
+// cr = CoderResult.malformedForLength(in.remaining());
+// // Fall through to malformed-input case
+// } else {
+// return cr;
+// }
+// }
+//
+// CodingErrorAction action = null;
+// if (cr.isMalformed())
+// action = malformedInputAction;
+// else if (cr.isUnmappable())
+// action = unmappableCharacterAction;
+// else
+// assert false : cr.toString();
+//
+// if (action == CodingErrorAction.REPORT)
+// return cr;
+//
+// if (action == CodingErrorAction.REPLACE) {
+// if (out.remaining() < replacement.length())
+// return CoderResult.OVERFLOW;
+// out.put(replacement);
+// }
+//
+// if ((action == CodingErrorAction.IGNORE)
+// || (action == CodingErrorAction.REPLACE)) {
+// // Skip erroneous input either way
+// in.position(in.position() + cr.length());
+// continue;
+// }
+//
+// assert false;
+// }
+//
+// }
/**
* Flushes this decoder.
@@ -645,19 +643,19 @@
* with a value of true for the endOfInput
* parameter
*/
- public final CoderResult flush(CharBuffer out) {
- if (state == ST_END) {
- CoderResult cr = implFlush(out);
- if (cr.isUnderflow())
- state = ST_FLUSHED;
- return cr;
- }
-
- if (state != ST_FLUSHED)
- throwIllegalStateException(state, ST_FLUSHED);
-
- return CoderResult.UNDERFLOW; // Already flushed
- }
+// public final CoderResult flush(CharBuffer out) {
+// if (state == ST_END) {
+// CoderResult cr = implFlush(out);
+// if (cr.isUnderflow())
+// state = ST_FLUSHED;
+// return cr;
+// }
+//
+// if (state != ST_FLUSHED)
+// throwIllegalStateException(state, ST_FLUSHED);
+//
+// return CoderResult.UNDERFLOW; // Already flushed
+// }
/**
* Flushes this decoder.
@@ -673,9 +671,9 @@
* @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
* {@link CoderResult#OVERFLOW}
*/
- protected CoderResult implFlush(CharBuffer out) {
- return CoderResult.UNDERFLOW;
- }
+// protected CoderResult implFlush(CharBuffer out) {
+// return CoderResult.UNDERFLOW;
+// }
/**
* Resets this decoder, clearing any internal state.
@@ -736,8 +734,8 @@
*
* @return A coder-result object describing the reason for termination
*/
- protected abstract CoderResult decodeLoop(ByteBuffer in,
- CharBuffer out);
+// protected abstract CoderResult decodeLoop(ByteBuffer in,
+// CharBuffer out);
/**
* Convenience method that decodes the remaining content of a single input
@@ -770,36 +768,36 @@
* the current unmappable-character action is {@link
* CodingErrorAction#REPORT}
*/
- public final CharBuffer decode(ByteBuffer in)
- throws CharacterCodingException
- {
- int n = (int)(in.remaining() * averageCharsPerByte());
- CharBuffer out = CharBuffer.allocate(n);
-
- if ((n == 0) && (in.remaining() == 0))
- return out;
- reset();
- for (;;) {
- CoderResult cr = in.hasRemaining() ?
- decode(in, out, true) : CoderResult.UNDERFLOW;
- if (cr.isUnderflow())
- cr = flush(out);
-
- if (cr.isUnderflow())
- break;
- if (cr.isOverflow()) {
- n = 2*n + 1; // Ensure progress; n might be 0!
- CharBuffer o = CharBuffer.allocate(n);
- out.flip();
- o.put(out);
- out = o;
- continue;
- }
- cr.throwException();
- }
- out.flip();
- return out;
- }
+// public final CharBuffer decode(ByteBuffer in)
+// throws CharacterCodingException
+// {
+// int n = (int)(in.remaining() * averageCharsPerByte());
+// CharBuffer out = CharBuffer.allocate(n);
+//
+// if ((n == 0) && (in.remaining() == 0))
+// return out;
+// reset();
+// for (;;) {
+// CoderResult cr = in.hasRemaining() ?
+// decode(in, out, true) : CoderResult.UNDERFLOW;
+// if (cr.isUnderflow())
+// cr = flush(out);
+//
+// if (cr.isUnderflow())
+// break;
+// if (cr.isOverflow()) {
+// n = 2*n + 1; // Ensure progress; n might be 0!
+// CharBuffer o = CharBuffer.allocate(n);
+// out.flip();
+// o.put(out);
+// out = o;
+// continue;
+// }
+// cr.throwException();
+// }
+// out.flip();
+// return out;
+// }
diff -r 44015f05c91b -r 802e5d2da9f6 rt/emul/compact/src/main/java/java/nio/charset/CharsetEncoder.java
--- a/rt/emul/compact/src/main/java/java/nio/charset/CharsetEncoder.java Fri Oct 04 15:01:04 2013 +0200
+++ b/rt/emul/compact/src/main/java/java/nio/charset/CharsetEncoder.java Fri Oct 04 15:02:17 2013 +0200
@@ -27,13 +27,13 @@
package java.nio.charset;
-import java.nio.Buffer;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
+//import java.nio.Buffer;
+//import java.nio.ByteBuffer;
+//import java.nio.CharBuffer;
+//import java.nio.BufferOverflowException;
+//import java.nio.BufferUnderflowException;
import java.lang.ref.WeakReference;
-import java.nio.charset.CoderMalfunctionError; // javadoc
+//import java.nio.charset.CoderMalfunctionError; // javadoc
/**
@@ -140,10 +140,10 @@
private final float maxBytesPerChar;
private byte[] replacement;
- private CodingErrorAction malformedInputAction
- = CodingErrorAction.REPORT;
- private CodingErrorAction unmappableCharacterAction
- = CodingErrorAction.REPORT;
+// private CodingErrorAction malformedInputAction
+// = CodingErrorAction.REPORT;
+// private CodingErrorAction unmappableCharacterAction
+// = CodingErrorAction.REPORT;
// Internal states
//
@@ -191,12 +191,10 @@
if (maxBytesPerChar <= 0.0f)
throw new IllegalArgumentException("Non-positive "
+ "maxBytesPerChar");
- if (!Charset.atBugLevel("1.4")) {
- if (averageBytesPerChar > maxBytesPerChar)
- throw new IllegalArgumentException("averageBytesPerChar"
- + " exceeds "
- + "maxBytesPerChar");
- }
+ if (averageBytesPerChar > maxBytesPerChar)
+ throw new IllegalArgumentException("averageBytesPerChar"
+ + " exceeds "
+ + "maxBytesPerChar");
this.replacement = replacement;
this.averageBytesPerChar = averageBytesPerChar;
this.maxBytesPerChar = maxBytesPerChar;
@@ -281,8 +279,8 @@
if (len > maxBytesPerChar)
throw new IllegalArgumentException("Replacement too long");
- if (!isLegalReplacement(newReplacement))
- throw new IllegalArgumentException("Illegal replacement");
+// if (!isLegalReplacement(newReplacement))
+// throw new IllegalArgumentException("Illegal replacement");
this.replacement = newReplacement;
implReplaceWith(newReplacement);
@@ -321,23 +319,23 @@
* @return true if, and only if, the given byte array
* is a legal replacement value for this encoder
*/
- public boolean isLegalReplacement(byte[] repl) {
- WeakReference wr = cachedDecoder;
- CharsetDecoder dec = null;
- if ((wr == null) || ((dec = wr.get()) == null)) {
- dec = charset().newDecoder();
- dec.onMalformedInput(CodingErrorAction.REPORT);
- dec.onUnmappableCharacter(CodingErrorAction.REPORT);
- cachedDecoder = new WeakReference(dec);
- } else {
- dec.reset();
- }
- ByteBuffer bb = ByteBuffer.wrap(repl);
- CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
- * dec.maxCharsPerByte()));
- CoderResult cr = dec.decode(bb, cb, true);
- return !cr.isError();
- }
+// public boolean isLegalReplacement(byte[] repl) {
+// WeakReference wr = cachedDecoder;
+// CharsetDecoder dec = null;
+// if ((wr == null) || ((dec = wr.get()) == null)) {
+// dec = charset().newDecoder();
+// dec.onMalformedInput(CodingErrorAction.REPORT);
+// dec.onUnmappableCharacter(CodingErrorAction.REPORT);
+// cachedDecoder = new WeakReference(dec);
+// } else {
+// dec.reset();
+// }
+// ByteBuffer bb = ByteBuffer.wrap(repl);
+// CharBuffer cb = CharBuffer.allocate((int)(bb.remaining()
+// * dec.maxCharsPerByte()));
+// CoderResult cr = dec.decode(bb, cb, true);
+// return !cr.isError();
+// }
@@ -346,9 +344,9 @@
*
* @return The current malformed-input action, which is never null
*/
- public CodingErrorAction malformedInputAction() {
- return malformedInputAction;
- }
+// public CodingErrorAction malformedInputAction() {
+// return malformedInputAction;
+// }
/**
* Changes this encoder's action for malformed-input errors.
@@ -363,13 +361,13 @@
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
- public final CharsetEncoder onMalformedInput(CodingErrorAction newAction) {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- malformedInputAction = newAction;
- implOnMalformedInput(newAction);
- return this;
- }
+// public final CharsetEncoder onMalformedInput(CodingErrorAction newAction) {
+// if (newAction == null)
+// throw new IllegalArgumentException("Null action");
+// malformedInputAction = newAction;
+// implOnMalformedInput(newAction);
+// return this;
+// }
/**
* Reports a change to this encoder's malformed-input action.
@@ -378,7 +376,7 @@
* should be overridden by encoders that require notification of changes to
* the malformed-input action.
*/
- protected void implOnMalformedInput(CodingErrorAction newAction) { }
+// protected void implOnMalformedInput(CodingErrorAction newAction) { }
/**
* Returns this encoder's current action for unmappable-character errors.
@@ -387,9 +385,9 @@
* @return The current unmappable-character action, which is never
* null
*/
- public CodingErrorAction unmappableCharacterAction() {
- return unmappableCharacterAction;
- }
+// public CodingErrorAction unmappableCharacterAction() {
+// return unmappableCharacterAction;
+// }
/**
* Changes this encoder's action for unmappable-character errors.
@@ -404,15 +402,15 @@
* @throws IllegalArgumentException
* If the precondition on the parameter does not hold
*/
- public final CharsetEncoder onUnmappableCharacter(CodingErrorAction
- newAction)
- {
- if (newAction == null)
- throw new IllegalArgumentException("Null action");
- unmappableCharacterAction = newAction;
- implOnUnmappableCharacter(newAction);
- return this;
- }
+// public final CharsetEncoder onUnmappableCharacter(CodingErrorAction
+// newAction)
+// {
+// if (newAction == null)
+// throw new IllegalArgumentException("Null action");
+// unmappableCharacterAction = newAction;
+// implOnUnmappableCharacter(newAction);
+// return this;
+// }
/**
* Reports a change to this encoder's unmappable-character action.
@@ -421,7 +419,7 @@
* should be overridden by encoders that require notification of changes to
* the unmappable-character action.
*/
- protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
+// protected void implOnUnmappableCharacter(CodingErrorAction newAction) { }
/**
* Returns the average number of bytes that will be produced for each
@@ -545,66 +543,66 @@
* If an invocation of the encodeLoop method threw
* an unexpected exception
*/
- public final CoderResult encode(CharBuffer in, ByteBuffer out,
- boolean endOfInput)
- {
- int newState = endOfInput ? ST_END : ST_CODING;
- if ((state != ST_RESET) && (state != ST_CODING)
- && !(endOfInput && (state == ST_END)))
- throwIllegalStateException(state, newState);
- state = newState;
-
- for (;;) {
-
- CoderResult cr;
- try {
- cr = encodeLoop(in, out);
- } catch (BufferUnderflowException x) {
- throw new CoderMalfunctionError(x);
- } catch (BufferOverflowException x) {
- throw new CoderMalfunctionError(x);
- }
-
- if (cr.isOverflow())
- return cr;
-
- if (cr.isUnderflow()) {
- if (endOfInput && in.hasRemaining()) {
- cr = CoderResult.malformedForLength(in.remaining());
- // Fall through to malformed-input case
- } else {
- return cr;
- }
- }
-
- CodingErrorAction action = null;
- if (cr.isMalformed())
- action = malformedInputAction;
- else if (cr.isUnmappable())
- action = unmappableCharacterAction;
- else
- assert false : cr.toString();
-
- if (action == CodingErrorAction.REPORT)
- return cr;
-
- if (action == CodingErrorAction.REPLACE) {
- if (out.remaining() < replacement.length)
- return CoderResult.OVERFLOW;
- out.put(replacement);
- }
-
- if ((action == CodingErrorAction.IGNORE)
- || (action == CodingErrorAction.REPLACE)) {
- // Skip erroneous input either way
- in.position(in.position() + cr.length());
- continue;
- }
-
- assert false;
- }
-
- }
+// public final CoderResult encode(CharBuffer in, ByteBuffer out,
+// boolean endOfInput)
+// {
+// int newState = endOfInput ? ST_END : ST_CODING;
+// if ((state != ST_RESET) && (state != ST_CODING)
+// && !(endOfInput && (state == ST_END)))
+// throwIllegalStateException(state, newState);
+// state = newState;
+//
+// for (;;) {
+//
+// CoderResult cr;
+// try {
+// cr = encodeLoop(in, out);
+// } catch (BufferUnderflowException x) {
+// throw new CoderMalfunctionError(x);
+// } catch (BufferOverflowException x) {
+// throw new CoderMalfunctionError(x);
+// }
+//
+// if (cr.isOverflow())
+// return cr;
+//
+// if (cr.isUnderflow()) {
+// if (endOfInput && in.hasRemaining()) {
+// cr = CoderResult.malformedForLength(in.remaining());
+// // Fall through to malformed-input case
+// } else {
+// return cr;
+// }
+// }
+//
+// CodingErrorAction action = null;
+// if (cr.isMalformed())
+// action = malformedInputAction;
+// else if (cr.isUnmappable())
+// action = unmappableCharacterAction;
+// else
+// assert false : cr.toString();
+//
+// if (action == CodingErrorAction.REPORT)
+// return cr;
+//
+// if (action == CodingErrorAction.REPLACE) {
+// if (out.remaining() < replacement.length)
+// return CoderResult.OVERFLOW;
+// out.put(replacement);
+// }
+//
+// if ((action == CodingErrorAction.IGNORE)
+// || (action == CodingErrorAction.REPLACE)) {
+// // Skip erroneous input either way
+// in.position(in.position() + cr.length());
+// continue;
+// }
+//
+// assert false;
+// }
+//
+// }
/**
* Flushes this encoder.
@@ -645,19 +643,19 @@
* with a value of true for the endOfInput
* parameter
*/
- public final CoderResult flush(ByteBuffer out) {
- if (state == ST_END) {
- CoderResult cr = implFlush(out);
- if (cr.isUnderflow())
- state = ST_FLUSHED;
- return cr;
- }
-
- if (state != ST_FLUSHED)
- throwIllegalStateException(state, ST_FLUSHED);
-
- return CoderResult.UNDERFLOW; // Already flushed
- }
+// public final CoderResult flush(ByteBuffer out) {
+// if (state == ST_END) {
+// CoderResult cr = implFlush(out);
+// if (cr.isUnderflow())
+// state = ST_FLUSHED;
+// return cr;
+// }
+//
+// if (state != ST_FLUSHED)
+// throwIllegalStateException(state, ST_FLUSHED);
+//
+// return CoderResult.UNDERFLOW; // Already flushed
+// }
/**
* Flushes this encoder.
@@ -673,9 +671,9 @@
* @return A coder-result object, either {@link CoderResult#UNDERFLOW} or
* {@link CoderResult#OVERFLOW}
*/
- protected CoderResult implFlush(ByteBuffer out) {
- return CoderResult.UNDERFLOW;
- }
+// protected CoderResult implFlush(ByteBuffer out) {
+// return CoderResult.UNDERFLOW;
+// }
/**
* Resets this encoder, clearing any internal state.
@@ -736,8 +734,8 @@
*
* @return A coder-result object describing the reason for termination
*/
- protected abstract CoderResult encodeLoop(CharBuffer in,
- ByteBuffer out);
+// protected abstract CoderResult encodeLoop(CharBuffer in,
+// ByteBuffer out);
/**
* Convenience method that encodes the remaining content of a single input
@@ -770,36 +768,38 @@
* the current unmappable-character action is {@link
* CodingErrorAction#REPORT}
*/
- public final ByteBuffer encode(CharBuffer in)
- throws CharacterCodingException
- {
- int n = (int)(in.remaining() * averageBytesPerChar());
- ByteBuffer out = ByteBuffer.allocate(n);
+// public final ByteBuffer encode(CharBuffer in)
+// throws CharacterCodingException
+// {
+// int n = (int)(in.remaining() * averageBytesPerChar());
+// ByteBuffer out = ByteBuffer.allocate(n);
+//
+// if ((n == 0) && (in.remaining() == 0))
+// return out;
+// reset();
+// for (;;) {
+// CoderResult cr = in.hasRemaining() ?
+// encode(in, out, true) : CoderResult.UNDERFLOW;
+// if (cr.isUnderflow())
+// cr = flush(out);
+//
+// if (cr.isUnderflow())
+// break;
+// if (cr.isOverflow()) {
+// n = 2*n + 1; // Ensure progress; n might be 0!
+// ByteBuffer o = ByteBuffer.allocate(n);
+// out.flip();
+// o.put(out);
+// out = o;
+// continue;
+// }
+// cr.throwException();
+// }
+// out.flip();
+// return out;
+// }
- if ((n == 0) && (in.remaining() == 0))
- return out;
- reset();
- for (;;) {
- CoderResult cr = in.hasRemaining() ?
- encode(in, out, true) : CoderResult.UNDERFLOW;
- if (cr.isUnderflow())
- cr = flush(out);
- if (cr.isUnderflow())
- break;
- if (cr.isOverflow()) {
- n = 2*n + 1; // Ensure progress; n might be 0!
- ByteBuffer o = ByteBuffer.allocate(n);
- out.flip();
- o.put(out);
- out = o;
- continue;
- }
- cr.throwException();
- }
- out.flip();
- return out;
- }
@@ -877,28 +877,26 @@
-
-
- private boolean canEncode(CharBuffer cb) {
- if (state == ST_FLUSHED)
- reset();
- else if (state != ST_RESET)
- throwIllegalStateException(state, ST_CODING);
- CodingErrorAction ma = malformedInputAction();
- CodingErrorAction ua = unmappableCharacterAction();
- try {
- onMalformedInput(CodingErrorAction.REPORT);
- onUnmappableCharacter(CodingErrorAction.REPORT);
- encode(cb);
- } catch (CharacterCodingException x) {
- return false;
- } finally {
- onMalformedInput(ma);
- onUnmappableCharacter(ua);
- reset();
- }
- return true;
- }
+// private boolean canEncode(CharBuffer cb) {
+// if (state == ST_FLUSHED)
+// reset();
+// else if (state != ST_RESET)
+// throwIllegalStateException(state, ST_CODING);
+// CodingErrorAction ma = malformedInputAction();
+// CodingErrorAction ua = unmappableCharacterAction();
+// try {
+// onMalformedInput(CodingErrorAction.REPORT);
+// onUnmappableCharacter(CodingErrorAction.REPORT);
+// encode(cb);
+// } catch (CharacterCodingException x) {
+// return false;
+// } finally {
+// onMalformedInput(ma);
+// onUnmappableCharacter(ua);
+// reset();
+// }
+// return true;
+// }
/**
* Tells whether or not this encoder can encode the given character.
@@ -923,12 +921,12 @@
* @throws IllegalStateException
* If an encoding operation is already in progress
*/
- public boolean canEncode(char c) {
- CharBuffer cb = CharBuffer.allocate(1);
- cb.put(c);
- cb.flip();
- return canEncode(cb);
- }
+// public boolean canEncode(char c) {
+// CharBuffer cb = CharBuffer.allocate(1);
+// cb.put(c);
+// cb.flip();
+// return canEncode(cb);
+// }
/**
* Tells whether or not this encoder can encode the given character
@@ -952,14 +950,14 @@
* @throws IllegalStateException
* If an encoding operation is already in progress
*/
- public boolean canEncode(CharSequence cs) {
- CharBuffer cb;
- if (cs instanceof CharBuffer)
- cb = ((CharBuffer)cs).duplicate();
- else
- cb = CharBuffer.wrap(cs.toString());
- return canEncode(cb);
- }
+// public boolean canEncode(CharSequence cs) {
+// CharBuffer cb;
+// if (cs instanceof CharBuffer)
+// cb = ((CharBuffer)cs).duplicate();
+// else
+// cb = CharBuffer.wrap(cs.toString());
+// return canEncode(cb);
+// }