|
From: <ls...@us...> - 2009-03-21 08:36:38
|
Revision: 5138
http://jnode.svn.sourceforge.net/jnode/?rev=5138&view=rev
Author: lsantha
Date: 2009-03-21 08:36:28 +0000 (Sat, 21 Mar 2009)
Log Message:
-----------
OpenJDK integration.
Added Paths:
-----------
trunk/core/src/openjdk/java/java/nio/charset/CoderMalfunctionError.java
trunk/core/src/openjdk/java/java/nio/charset/CoderResult.java
trunk/core/src/openjdk/java/java/nio/charset/CodingErrorAction.java
trunk/core/src/openjdk/java/java/nio/charset/MalformedInputException.java
trunk/core/src/openjdk/java/java/nio/charset/UnmappableCharacterException.java
trunk/core/src/openjdk/java/java/nio/charset/spi/
trunk/core/src/openjdk/java/java/nio/charset/spi/CharsetProvider.java
trunk/core/src/openjdk/java/java/nio/charset/spi/package.html
Removed Paths:
-------------
trunk/core/src/classpath/java/java/nio/charset/CoderMalfunctionError.java
trunk/core/src/classpath/java/java/nio/charset/CoderResult.java
trunk/core/src/classpath/java/java/nio/charset/CodingErrorAction.java
trunk/core/src/classpath/java/java/nio/charset/MalformedInputException.java
trunk/core/src/classpath/java/java/nio/charset/UnmappableCharacterException.java
trunk/core/src/classpath/java/java/nio/charset/spi/
Deleted: trunk/core/src/classpath/java/java/nio/charset/CoderMalfunctionError.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/CoderMalfunctionError.java 2009-03-21 04:33:32 UTC (rev 5137)
+++ trunk/core/src/classpath/java/java/nio/charset/CoderMalfunctionError.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -1,54 +0,0 @@
-/* CoderMalfunctionError.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio.charset;
-
-/**
- * @since 1.4
- */
-public class CoderMalfunctionError extends Error
-{
- private static final long serialVersionUID = - 1151412348057794301L;
-
- /**
- * Creates the error
- */
- public CoderMalfunctionError(Exception cause)
- {
- super (cause);
- }
-}
Deleted: trunk/core/src/classpath/java/java/nio/charset/CoderResult.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/CoderResult.java 2009-03-21 04:33:32 UTC (rev 5137)
+++ trunk/core/src/classpath/java/java/nio/charset/CoderResult.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -1,189 +0,0 @@
-/* CoderResult.java --
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio.charset;
-
-import java.lang.ref.WeakReference;
-import java.nio.BufferOverflowException;
-import java.nio.BufferUnderflowException;
-import java.util.HashMap;
-
-/**
- * @author Jesse Rosenstock
- * @since 1.4
- */
-public class CoderResult
-{
- private static final int TYPE_MALFORMED = 0;
- private static final int TYPE_OVERFLOW = 1;
- private static final int TYPE_UNDERFLOW = 2;
- private static final int TYPE_UNMAPPABLE = 3;
-
- public static final CoderResult OVERFLOW
- = new CoderResult (TYPE_OVERFLOW, 0);
- public static final CoderResult UNDERFLOW
- = new CoderResult (TYPE_UNDERFLOW, 0);
-
- private static final String[] names
- = { "MALFORMED", "OVERFLOW", "UNDERFLOW", "UNMAPPABLE" };
-
- private static final Cache malformedCache
- = new Cache ()
- {
- protected CoderResult make (int length)
- {
- return new CoderResult (TYPE_MALFORMED, length);
- }
- };
-
- private static final Cache unmappableCache
- = new Cache ()
- {
- protected CoderResult make (int length)
- {
- return new CoderResult (TYPE_UNMAPPABLE, length);
- }
- };
-
- private final int type;
- private final int length;
-
- // Package-private to avoid a trampoline constructor.
- CoderResult (int type, int length)
- {
- this.type = type;
- this.length = length;
- }
-
- public boolean isError ()
- {
- return length > 0;
- }
-
- public boolean isMalformed ()
- {
- return type == TYPE_MALFORMED;
- }
-
- public boolean isOverflow ()
- {
- return type == TYPE_OVERFLOW;
- }
-
- public boolean isUnderflow ()
- {
- return type == TYPE_UNDERFLOW;
- }
-
- public boolean isUnmappable ()
- {
- return type == TYPE_UNMAPPABLE;
- }
-
- public int length ()
- {
- if (length <= 0)
- throw new UnsupportedOperationException ();
- else
- return length;
- }
-
- public static CoderResult malformedForLength (int length)
- {
- return malformedCache.get (length);
- }
-
- public void throwException ()
- throws CharacterCodingException
- {
- switch (type)
- {
- case TYPE_MALFORMED:
- throw new MalformedInputException (length);
- case TYPE_OVERFLOW:
- throw new BufferOverflowException ();
- case TYPE_UNDERFLOW:
- throw new BufferUnderflowException ();
- case TYPE_UNMAPPABLE:
- throw new UnmappableCharacterException (length);
- }
- }
-
- public String toString ()
- {
- String name = names[type];
- return (length > 0) ? name + '[' + length + ']' : name;
- }
-
- public static CoderResult unmappableForLength (int length)
- {
- return unmappableCache.get (length);
- }
-
- private abstract static class Cache
- {
- private final HashMap cache;
-
- // Package-private to avoid a trampoline constructor.
- Cache ()
- {
- cache = new HashMap ();
- }
-
- // Package-private to avoid a trampoline.
- synchronized CoderResult get (int length)
- {
- if (length <= 0)
- throw new IllegalArgumentException ("Non-positive length");
-
- Integer len = new Integer (length);
- CoderResult cr = null;
- Object o;
- if ((o = cache.get (len)) != null)
- cr = (CoderResult) ((WeakReference) o).get ();
- if (cr == null)
- {
- cr = make (length);
- cache.put (len, new WeakReference (cr));
- }
-
- return cr;
- }
-
- protected abstract CoderResult make (int length);
- }
-}
Deleted: trunk/core/src/classpath/java/java/nio/charset/CodingErrorAction.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/CodingErrorAction.java 2009-03-21 04:33:32 UTC (rev 5137)
+++ trunk/core/src/classpath/java/java/nio/charset/CodingErrorAction.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -1,66 +0,0 @@
-/* CodingErrorAction.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio.charset;
-
-public class CodingErrorAction
-{
- public static final CodingErrorAction IGNORE
- = new CodingErrorAction("ignore");
- public static final CodingErrorAction REPLACE
- = new CodingErrorAction("replace");
- public static final CodingErrorAction REPORT
- = new CodingErrorAction("report");
-
- private final String name;
-
- /**
- * Private constructor only used to create the constant CodingErrorActions.
- */
- private CodingErrorAction(String name)
- {
- this.name = name;
- }
-
- /**
- * Returns the name of the CodingErrorAction.
- */
- public String toString ()
- {
- return name;
- }
-}
Deleted: trunk/core/src/classpath/java/java/nio/charset/MalformedInputException.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/MalformedInputException.java 2009-03-21 04:33:32 UTC (rev 5137)
+++ trunk/core/src/classpath/java/java/nio/charset/MalformedInputException.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -1,79 +0,0 @@
-/* MalformedInputException.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio.charset;
-
-/**
- * @since 1.4
- */
-public class MalformedInputException extends CharacterCodingException
-{
- private static final long serialVersionUID = - 3438823399834806194L;
-
- private int inputLength;
-
- /**
- * Creates the exception
- *
- * @param inputLength the position of malformed input in the input stream
- */
- public MalformedInputException (int inputLength)
- {
- super ();
- this.inputLength = inputLength;
- }
-
- /**
- * Retrieves the position of the malformed input in the input stream.
- *
- * @return the position
- */
- public int getInputLength ()
- {
- return inputLength;
- }
-
- /**
- * Returns the detail message string of this throwable
- *
- * @return the message
- */
- public String getMessage ()
- {
- return "Input length = " + inputLength;
- }
-}
Deleted: trunk/core/src/classpath/java/java/nio/charset/UnmappableCharacterException.java
===================================================================
--- trunk/core/src/classpath/java/java/nio/charset/UnmappableCharacterException.java 2009-03-21 04:33:32 UTC (rev 5137)
+++ trunk/core/src/classpath/java/java/nio/charset/UnmappableCharacterException.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -1,73 +0,0 @@
-/* UnmappableCharacterException.java --
- Copyright (C) 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio.charset;
-
-/**
- * @since 1.4
- */
-public class UnmappableCharacterException extends CharacterCodingException
-{
- private static final long serialVersionUID = - 7026962371537706123L;
-
- private int inputLength;
-
- /**
- * Creates the exception
- */
- public UnmappableCharacterException (int inputLength)
- {
- super ();
- this.inputLength = inputLength;
- }
-
- /**
- * Retrieves the illegal charset name
- */
- public int getInputLength ()
- {
- return inputLength;
- }
-
- /**
- * Returns the detail message string of this throwable
- */
- public String getMessage ()
- {
- return "Input length = " + inputLength;
- }
-}
Added: trunk/core/src/openjdk/java/java/nio/charset/CoderMalfunctionError.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/CoderMalfunctionError.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/CoderMalfunctionError.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Error thrown when the {@link CharsetDecoder#decodeLoop decodeLoop} method of
+ * a {@link CharsetDecoder}, or the {@link CharsetEncoder#encodeLoop
+ * encodeLoop} method of a {@link CharsetEncoder}, throws an unexpected
+ * exception.
+ *
+ * @since 1.4
+ */
+
+public class CoderMalfunctionError
+ extends Error
+{
+
+ private static final long serialVersionUID = -1151412348057794301L;
+
+ /**
+ * Initializes an instance of this class.
+ *
+ * @param cause
+ * The unexpected exception that was thrown
+ */
+ public CoderMalfunctionError(Exception cause) {
+ super(cause);
+ }
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/CoderResult.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/CoderResult.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/CoderResult.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,284 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset;
+
+import java.lang.ref.WeakReference;
+import java.nio.*;
+import java.util.Map;
+import java.util.HashMap;
+
+
+/**
+ * A description of the result state of a coder.
+ *
+ * <p> A charset coder, that is, either a decoder or an encoder, consumes bytes
+ * (or characters) from an input buffer, translates them, and writes the
+ * resulting characters (or bytes) to an output buffer. A coding process
+ * terminates for one of four categories of reasons, which are described by
+ * instances of this class:
+ *
+ * <ul>
+ *
+ * <li><p> <i>Underflow</i> is reported when there is no more input to be
+ * processed, or there is insufficient input and additional input is
+ * required. This condition is represented by the unique result object
+ * {@link #UNDERFLOW}, whose {@link #isUnderflow() isUnderflow} method
+ * returns <tt>true</tt>. </p></li>
+ *
+ * <li><p> <i>Overflow</i> is reported when there is insufficient room
+ * remaining in the output buffer. This condition is represented by the
+ * unique result object {@link #OVERFLOW}, whose {@link #isOverflow()
+ * isOverflow} method returns <tt>true</tt>. </p></li>
+ *
+ * <li><p> A <i>malformed-input error</i> is reported when a sequence of
+ * input units is not well-formed. Such errors are described by instances of
+ * this class whose {@link #isMalformed() isMalformed} method returns
+ * <tt>true</tt> and whose {@link #length() length} method returns the length
+ * of the malformed sequence. There is one unique instance of this class for
+ * all malformed-input errors of a given length. </p></li>
+ *
+ * <li><p> An <i>unmappable-character error</i> is reported when a sequence
+ * of input units denotes a character that cannot be represented in the
+ * output charset. Such errors are described by instances of this class
+ * whose {@link #isUnmappable() isUnmappable} method returns <tt>true</tt> and
+ * whose {@link #length() length} method returns the length of the input
+ * sequence denoting the unmappable character. There is one unique instance
+ * of this class for all unmappable-character errors of a given length.
+ * </p></li>
+ *
+ * </ul>
+ *
+ * For convenience, the {@link #isError() isError} method returns <tt>true</tt>
+ * for result objects that describe malformed-input and unmappable-character
+ * errors but <tt>false</tt> for those that describe underflow or overflow
+ * conditions. </p>
+ *
+ *
+ * @author Mark Reinhold
+ * @author JSR-51 Expert Group
+ * @since 1.4
+ */
+
+public class CoderResult {
+
+ private static final int CR_UNDERFLOW = 0;
+ private static final int CR_OVERFLOW = 1;
+ private static final int CR_ERROR_MIN = 2;
+ private static final int CR_MALFORMED = 2;
+ private static final int CR_UNMAPPABLE = 3;
+
+ private static final String[] names
+ = { "UNDERFLOW", "OVERFLOW", "MALFORMED", "UNMAPPABLE" };
+
+ private final int type;
+ private final int length;
+
+ private CoderResult(int type, int length) {
+ this.type = type;
+ this.length = length;
+ }
+
+ /**
+ * Returns a string describing this coder result.
+ *
+ * @return A descriptive string
+ */
+ public String toString() {
+ String nm = names[type];
+ return isError() ? nm + "[" + length + "]" : nm;
+ }
+
+ /**
+ * Tells whether or not this object describes an underflow condition. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this object denotes underflow
+ */
+ public boolean isUnderflow() {
+ return (type == CR_UNDERFLOW);
+ }
+
+ /**
+ * Tells whether or not this object describes an overflow condition. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this object denotes overflow
+ */
+ public boolean isOverflow() {
+ return (type == CR_OVERFLOW);
+ }
+
+ /**
+ * Tells whether or not this object describes an error condition. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this object denotes either a
+ * malformed-input error or an unmappable-character error
+ */
+ public boolean isError() {
+ return (type >= CR_ERROR_MIN);
+ }
+
+ /**
+ * Tells whether or not this object describes a malformed-input error.
+ * </p>
+ *
+ * @return <tt>true</tt> if, and only if, this object denotes a
+ * malformed-input error
+ */
+ public boolean isMalformed() {
+ return (type == CR_MALFORMED);
+ }
+
+ /**
+ * Tells whether or not this object describes an unmappable-character
+ * error. </p>
+ *
+ * @return <tt>true</tt> if, and only if, this object denotes an
+ * unmappable-character error
+ */
+ public boolean isUnmappable() {
+ return (type == CR_UNMAPPABLE);
+ }
+
+ /**
+ * Returns the length of the erroneous input described by this
+ * object <i>(optional operation)</i>. </p>
+ *
+ * @return The length of the erroneous input, a positive integer
+ *
+ * @throws UnsupportedOperationException
+ * If this object does not describe an error condition, that is,
+ * if the {@link #isError() isError} does not return <tt>true</tt>
+ */
+ public int length() {
+ if (!isError())
+ throw new UnsupportedOperationException();
+ return length;
+ }
+
+ /**
+ * Result object indicating underflow, meaning that either the input buffer
+ * has been completely consumed or, if the input buffer is not yet empty,
+ * that additional input is required. </p>
+ */
+ public static final CoderResult UNDERFLOW
+ = new CoderResult(CR_UNDERFLOW, 0);
+
+ /**
+ * Result object indicating overflow, meaning that there is insufficient
+ * room in the output buffer. </p>
+ */
+ public static final CoderResult OVERFLOW
+ = new CoderResult(CR_OVERFLOW, 0);
+
+ private static abstract class Cache {
+
+ private Map cache = null;
+
+ protected abstract CoderResult create(int len);
+
+ private synchronized CoderResult get(int len) {
+ if (len <= 0)
+ throw new IllegalArgumentException("Non-positive length");
+ Integer k = new Integer(len);
+ WeakReference w;
+ CoderResult e = null;
+ if (cache == null) {
+ cache = new HashMap();
+ } else if ((w = (WeakReference)cache.get(k)) != null) {
+ e = (CoderResult)w.get();
+ }
+ if (e == null) {
+ e = create(len);
+ cache.put(k, new WeakReference(e));
+ }
+ return e;
+ }
+
+ }
+
+ private static Cache malformedCache
+ = new Cache() {
+ public CoderResult create(int len) {
+ return new CoderResult(CR_MALFORMED, len);
+ }};
+
+ /**
+ * Static factory method that returns the unique object describing a
+ * malformed-input error of the given length. </p>
+ *
+ * @return The requested coder-result object
+ */
+ public static CoderResult malformedForLength(int length) {
+ return malformedCache.get(length);
+ }
+
+ private static Cache unmappableCache
+ = new Cache() {
+ public CoderResult create(int len) {
+ return new CoderResult(CR_UNMAPPABLE, len);
+ }};
+
+ /**
+ * Static factory method that returns the unique result object describing
+ * an unmappable-character error of the given length. </p>
+ *
+ * @return The requested coder-result object
+ */
+ public static CoderResult unmappableForLength(int length) {
+ return unmappableCache.get(length);
+ }
+
+ /**
+ * Throws an exception appropriate to the result described by this object.
+ * </p>
+ *
+ * @throws BufferUnderflowException
+ * If this object is {@link #UNDERFLOW}
+ *
+ * @throws BufferOverflowException
+ * If this object is {@link #OVERFLOW}
+ *
+ * @throws MalformedInputException
+ * If this object represents a malformed-input error; the
+ * exception's length value will be that of this object
+ *
+ * @throws UnmappableCharacterException
+ * If this object represents an unmappable-character error; the
+ * exceptions length value will be that of this object
+ */
+ public void throwException()
+ throws CharacterCodingException
+ {
+ switch (type) {
+ case CR_UNDERFLOW: throw new BufferUnderflowException();
+ case CR_OVERFLOW: throw new BufferOverflowException();
+ case CR_MALFORMED: throw new MalformedInputException(length);
+ case CR_UNMAPPABLE: throw new UnmappableCharacterException(length);
+ default:
+ assert false;
+ }
+ }
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/CodingErrorAction.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/CodingErrorAction.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/CodingErrorAction.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2001-2002 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * A typesafe enumeration for coding-error actions.
+ *
+ * <p> Instances of this class are used to specify how malformed-input and
+ * unmappable-character errors are to be handled by charset <a
+ * href="CharsetDecoder.html#cae">decoders</a> and <a
+ * href="CharsetEncoder.html#cae">encoders</a>. </p>
+ *
+ *
+ * @author Mark Reinhold
+ * @author JSR-51 Expert Group
+ * @since 1.4
+ */
+
+public class CodingErrorAction {
+
+ private String name;
+
+ private CodingErrorAction(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Action indicating that a coding error is to be handled by dropping the
+ * erroneous input and resuming the coding operation. </p>
+ */
+ public static final CodingErrorAction IGNORE
+ = new CodingErrorAction("IGNORE");
+
+ /**
+ * Action indicating that a coding error is to be handled by dropping the
+ * erroneous input, appending the coder's replacement value to the output
+ * buffer, and resuming the coding operation. </p>
+ */
+ public static final CodingErrorAction REPLACE
+ = new CodingErrorAction("REPLACE");
+
+ /**
+ * Action indicating that a coding error is to be reported, either by
+ * returning a {@link CoderResult} object or by throwing a {@link
+ * CharacterCodingException}, whichever is appropriate for the method
+ * implementing the coding process.
+ */
+ public static final CodingErrorAction REPORT
+ = new CodingErrorAction("REPORT");
+
+ /**
+ * Returns a string describing this action. </p>
+ *
+ * @return A descriptive string
+ */
+ public String toString() {
+ return name;
+ }
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/MalformedInputException.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/MalformedInputException.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/MalformedInputException.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Checked exception thrown when an input byte sequence is not legal for given
+ * charset, or an input character sequence is not a legal sixteen-bit Unicode
+ * sequence.
+ *
+ * @since 1.4
+ */
+
+public class MalformedInputException
+ extends CharacterCodingException
+{
+
+ private static final long serialVersionUID = -3438823399834806194L;
+
+ private int inputLength;
+
+ public MalformedInputException(int inputLength) {
+ this.inputLength = inputLength;
+ }
+
+ public int getInputLength() {
+ return inputLength;
+ }
+
+ public String getMessage() {
+ return "Input length = " + inputLength;
+ }
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/UnmappableCharacterException.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/UnmappableCharacterException.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/UnmappableCharacterException.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Checked exception thrown when an input character (or byte) sequence
+ * is valid but cannot be mapped to an output byte (or character)
+ * sequence. </p>
+ *
+ * @since 1.4
+ */
+
+public class UnmappableCharacterException
+ extends CharacterCodingException
+{
+
+ private static final long serialVersionUID = -7026962371537706123L;
+
+ private int inputLength;
+
+ public UnmappableCharacterException(int inputLength) {
+ this.inputLength = inputLength;
+ }
+
+ public int getInputLength() {
+ return inputLength;
+ }
+
+ public String getMessage() {
+ return "Input length = " + inputLength;
+ }
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/spi/CharsetProvider.java
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/spi/CharsetProvider.java (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/spi/CharsetProvider.java 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2000-2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package java.nio.charset.spi;
+
+import java.nio.charset.Charset;
+import java.util.Iterator;
+
+
+/**
+ * Charset service-provider class.
+ *
+ * <p> A charset provider is a concrete subclass of this class that has a
+ * zero-argument constructor and some number of associated charset
+ * implementation classes. Charset providers may be installed in an instance
+ * of the Java platform as extensions, that is, jar files placed into any of
+ * the usual extension directories. Providers may also be made available by
+ * adding them to the applet or application class path or by some other
+ * platform-specific means. Charset providers are looked up via the current
+ * thread's {@link java.lang.Thread#getContextClassLoader() </code>context
+ * class loader<code>}.
+ *
+ * <p> A charset provider identifies itself with a provider-configuration file
+ * named <tt>java.nio.charset.spi.CharsetProvider</tt> in the resource
+ * directory <tt>META-INF/services</tt>. The file should contain a list of
+ * fully-qualified concrete charset-provider class names, one per line. A line
+ * is terminated by any one of a line feed (<tt>'\n'</tt>), a carriage return
+ * (<tt>'\r'</tt>), or a carriage return followed immediately by a line feed.
+ * Space and tab characters surrounding each name, as well as blank lines, are
+ * ignored. The comment character is <tt>'#'</tt> (<tt>'\u0023'</tt>); on
+ * each line all characters following the first comment character are ignored.
+ * The file must be encoded in UTF-8.
+ *
+ * <p> If a particular concrete charset provider class is named in more than
+ * one configuration file, or is named in the same configuration file more than
+ * once, then the duplicates will be ignored. The configuration file naming a
+ * particular provider need not be in the same jar file or other distribution
+ * unit as the provider itself. The provider must be accessible from the same
+ * class loader that was initially queried to locate the configuration file;
+ * this is not necessarily the class loader that loaded the file. </p>
+ *
+ *
+ * @author Mark Reinhold
+ * @author JSR-51 Expert Group
+ * @since 1.4
+ *
+ * @see java.nio.charset.Charset
+ */
+
+public abstract class CharsetProvider {
+
+ /**
+ * Initializes a new charset provider. </p>
+ *
+ * @throws SecurityException
+ * If a security manager has been installed and it denies
+ * {@link RuntimePermission}<tt>("charsetProvider")</tt>
+ */
+ protected CharsetProvider() {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission("charsetProvider"));
+ }
+
+ /**
+ * Creates an iterator that iterates over the charsets supported by this
+ * provider. This method is used in the implementation of the {@link
+ * java.nio.charset.Charset#availableCharsets Charset.availableCharsets}
+ * method. </p>
+ *
+ * @return The new iterator
+ */
+ public abstract Iterator<Charset> charsets();
+
+ /**
+ * Retrieves a charset for the given charset name. </p>
+ *
+ * @param charsetName
+ * The name of the requested charset; may be either
+ * a canonical name or an alias
+ *
+ * @return A charset object for the named charset,
+ * or <tt>null</tt> if the named charset
+ * is not supported by this provider
+ */
+ public abstract Charset charsetForName(String charsetName);
+
+}
Added: trunk/core/src/openjdk/java/java/nio/charset/spi/package.html
===================================================================
--- trunk/core/src/openjdk/java/java/nio/charset/spi/package.html (rev 0)
+++ trunk/core/src/openjdk/java/java/nio/charset/spi/package.html 2009-03-21 08:36:28 UTC (rev 5138)
@@ -0,0 +1,45 @@
+<!--
+ Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+
+ This code is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License version 2 only, as
+ published by the Free Software Foundation. Sun designates this
+ particular file as subject to the "Classpath" exception as provided
+ by Sun in the LICENSE file that accompanied this code.
+
+ This code is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ version 2 for more details (a copy is included in the LICENSE file that
+ accompanied this code).
+
+ You should have received a copy of the GNU General Public License version
+ 2 along with this work; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+ Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ CA 95054 USA or visit www.sun.com if you need additional information or
+ have any questions.
+-->
+
+<!doctype html public "-//IETF//DTD HTML//EN">
+<html>
+<body bgcolor="white">
+
+Service-provider classes for the <tt>{@link java.nio.charset}</tt> package.
+
+<p> Only developers who are defining new charsets should need to make direct
+use of this package. </p>
+
+<p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor
+or method in any class or interface in this package will cause a {@link
+java.lang.NullPointerException NullPointerException} to be thrown.
+
+
+@since 1.4
+@author Mark Reinhold
+@author JSR-51 Expert Group
+
+</body>
+</html>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|