harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ge...@apache.org
Subject svn commit: r350181 [131/198] - in /incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/ depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/ depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/ depends/oss/win....
Date Thu, 01 Dec 2005 06:04:00 GMT
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CharsetEncoder.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CharsetEncoder.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CharsetEncoder.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CharsetEncoder.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,755 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+
+/**
+ * An converter that can convert 16-bit Unicode character sequence to byte
+ * sequence in some charset .
+ * <p>
+ * The input character sequence is wrapped by
+ * {@link java.nio.CharBuffer CharBuffer} and the output character sequence is
+ * {@link java.nio.ByteBuffer ByteBuffer}. A encoder instance should be used in
+ * following sequence, which is referred to as a encoding operation:
+ * <ol>
+ * <li>Invoking the {@link #reset() reset} method to reset the encoder if the
+ * encoder has been used;</li> <li>Invoking the
+ * {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method until the
+ * addtional input is not needed, the <code>endOfInput</code> parameter must
+ * be set to false, the input buffer must be filled and the output buffer must
+ * be flushed between invocations;</li> <li>Invoking the
+ * {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method last time, and
+ * the the <code>endOfInput</code> parameter must be set to true</li>
+ * <li>Invoking the {@link #flush(ByteBuffer) flush} method to flush the output.</li>
+ * </ol>
+ * </p>
+ * <p>
+ * The {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method will
+ * convert as many characters as possible, and the process won't stop except the
+ * input characters has been run out of, the output buffer has been filled or
+ * some error has happened. A {@link CoderResult CoderResult} instance will be
+ * returned to indicate the stop reason, and the invoker can identify the result
+ * and choose further action, which can include filling the input buffer,
+ * flushing the output buffer, recovering from error and trying again.
+ * </p>
+ * <p>
+ * There are two common encoding errors. One is named as malformed and it is
+ * returned when the input content is illegal 16-bit Unicode character sequence,
+ * the other is named as unmappable character and occurs when there is a problem
+ * mapping the input to a valid byte sequence in the specific charset.
+ * </p>
+ * <p>
+ * The two errors can be handled in three ways, the default one is to report the
+ * error to the invoker by a {@link CoderResult CoderResult} instance, and the
+ * alternatives are to ignore it or to replace the erroneous input with the
+ * replacement byte array. The replacement byte array is {(byte)'?'} by default
+ * and can be changed by invoking {@link #replaceWith(byte[]) replaceWith}
+ * method. The invoker of this encoder can choose one way by specifing a
+ * {@link CodingErrorAction CodingErrorAction} instance for each error type via
+ * {@link #onMalformedInput(CodingErrorAction) onMalformedInput} method and
+ * {@link #onUnmappableCharacter(CodingErrorAction) onUnmappableCharacter}
+ * method.
+ * </p>
+ * <p>
+ * This class is abstract class and encapsulate many common operations of
+ * encoding process for all charsets. encoder for specific charset should extend
+ * this class and need only implement
+ * {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop} method for basic
+ * encoding loop. If a subclass mantains internl state, it should override the
+ * {@link #implFlush(ByteBuffer) implFlush} method and
+ * {@link #implReset() implReset} method in addition.
+ * </p>
+ * <p>
+ * This class is not thread-safe.
+ * </p>
+ * 
+ * @see java.nio.charset.Charset
+ * @see java.nio.charset.CharsetDecoder
+ */
+public abstract class CharsetEncoder {
+	/*
+	 * --------------------------------------- Consts
+	 * ---------------------------------------
+	 */
+	/*
+	 * internal status consts
+	 */
+	private static final int INIT = 0;
+
+	private static final int ONGOING = 1;
+
+	private static final int END = 2;
+
+	private static final int FLUSH = 3;
+
+	/*
+	 * --------------------------------------- Instance variables
+	 * ---------------------------------------
+	 */
+	// the Charset which creates this encoder
+	private Charset cs;
+
+	// average bytes per character created by this encoder
+	private float averBytes;
+
+	// maximum bytes per character can be created by this encoder
+	private float maxBytes;
+
+	// replacement byte array
+	private byte[] replace;
+
+	// internal status
+	private int status;
+
+	// action for malformed input
+	private CodingErrorAction malformAction;
+
+	// action for unmapped char input
+	private CodingErrorAction unmapAction;
+
+	// decoder instance for this encoder's charset, used for replacement value
+	// checking
+	private CharsetDecoder decoder;
+
+	/*
+	 * --------------------------------------- Constructors
+	 * ---------------------------------------
+	 */
+
+	/**
+	 * Construct a new <code>CharsetEncoder</code> using given
+	 * <code>Charset</code>, average number and maximum number of bytes
+	 * created by this encoder for one input character.
+	 * 
+	 * @param cs
+	 *            this encoder's <code>Charset</code>, which create this
+	 *            encoder
+	 * @param averageBytesPerChar
+	 *            average number of bytes created by this encoder for one input
+	 *            character, must be positive
+	 * @param maxBytesPerChar
+	 *            maximum number of bytes which can be created by this encoder
+	 *            for one input character, must be positive
+	 * @throws IllegalArgumentException
+	 *             if <code>maxBytesPerChar</code> or
+	 *             <code>averageBytePerChar</code> is negative
+	 */
+	protected CharsetEncoder(Charset cs, float averageBytesPerChar,
+			float maxBytesPerChar) {
+		this(cs, averageBytesPerChar, maxBytesPerChar,
+				new byte[] { (byte) '?' });
+	}
+
+	/**
+	 * Construct a new <code>CharsetEncoder</code> using given
+	 * <code>Charset</code>, replace byte array, average number and maximum
+	 * number of bytes created by this encoder for one input character.
+	 * 
+	 * @param cs
+	 *            the this encoder's <code>Charset</code>, which create this
+	 *            encoder
+	 * @param averageBytesPerChar
+	 *            average number of bytes created by this encoder for single
+	 *            input character, must be positive
+	 * @param maxBytesPerChar
+	 *            maximum number of bytes which can be created by this encoder
+	 *            for single input character, must be positive
+	 * @param replacement
+	 *            the replacement byte array, cannot be null or empty, its
+	 *            length cannot larger than <code>maxBytesPerChar</code>, and
+	 *            must be legal replacement, which can be justified by
+	 *            {@link #isLegalReplacement(byte[]) isLegalReplacement}
+	 * @throws IllegalArgumentException
+	 *             if any parameters are invalid
+	 */
+	protected CharsetEncoder(Charset cs, float averageBytesPerChar,
+			float maxBytesPerChar, byte[] replacement) {
+		if (averageBytesPerChar <= 0 || maxBytesPerChar <= 0) {
+			throw new IllegalArgumentException(
+					"Bytes number for one character must be positive."); //$NON-NLS-1$
+		}
+		this.cs = cs;
+		averBytes = averageBytesPerChar;
+		maxBytes = maxBytesPerChar;
+		status = INIT;
+		malformAction = CodingErrorAction.REPORT;
+		unmapAction = CodingErrorAction.REPORT;
+		decoder = cs.newDecoder();
+		replaceWith(replacement);
+	}
+
+	/*
+	 * --------------------------------------- Methods
+	 * ---------------------------------------
+	 */
+	/**
+	 * get the average number of bytes created by this encoder for single input
+	 * character
+	 * 
+	 * @return the average number of bytes created by this encoder for single
+	 *         input character
+	 */
+	public final float averageBytesPerChar() {
+		return averBytes;
+	}
+
+	/**
+	 * Check if given character can be encoded by this encoder.
+	 * 
+	 * Note that this method can change the internal status of this encoder, so
+	 * it should not be called when another encode process is ongoing, otherwise
+	 * it will throw <code>IllegalStateException</code>.
+	 * 
+	 * This method can be overriden for performance improvement.
+	 * 
+	 * @param c
+	 *            the given encoder
+	 * @return true if given character can be encoded by this encoder
+	 * @throws IllegalStateException
+	 *             if another encode process is ongoing so that current internal
+	 *             status is neigher RESET or FLUSH
+	 */
+	public boolean canEncode(char c) {
+		return implCanEncode(CharBuffer.wrap(new char[] { c }));
+	}
+
+	// implementation of canEncode
+	private boolean implCanEncode(CharBuffer cb) {
+		if (status == FLUSH) {
+			status = INIT;
+		}
+		if (status != INIT) {
+			throw new IllegalStateException(
+					"Another encoding process is ongoing!"); //$NON-NLS-1$
+		}
+		CodingErrorAction malformBak = malformAction;
+		CodingErrorAction unmapBak = unmapAction;
+		onMalformedInput(CodingErrorAction.REPORT);
+		onUnmappableCharacter(CodingErrorAction.REPORT);
+		boolean result = true;
+		try {
+			this.encode(cb);
+		} catch (CharacterCodingException e) {
+			result = false;
+		}
+		onMalformedInput(malformBak);
+		onUnmappableCharacter(unmapBak);
+		reset();
+		return result;
+	}
+
+	/**
+	 * Check if given <code>CharSequence</code> can be encoded by this
+	 * encoder.
+	 * 
+	 * Note that this method can change the internal status of this encoder, so
+	 * it should not be called when another encode process is ongoing, otherwise
+	 * it will throw <code>IllegalStateException</code>.
+	 * 
+	 * This method can be overriden for performance improvement.
+	 * 
+	 * @param sequence
+	 *            the given <code>CharSequence</code>
+	 * @return true if given <code>CharSequence</code> can be encoded by this
+	 *         encoder
+	 * @throws IllegalStateException
+	 *             if current internal status is neigher RESET or FLUSH
+	 */
+	public boolean canEncode(CharSequence sequence) {
+		CharBuffer cb;
+		if (sequence instanceof CharBuffer) {
+			cb = ((CharBuffer) sequence).duplicate();
+		} else {
+			cb = CharBuffer.wrap(sequence);
+		}
+		return implCanEncode(cb);
+	}
+
+	/**
+	 * Get the <code>Charset</code> which creates this encoder.
+	 * 
+	 * @return the <code>Charset</code> which creates this encoder
+	 */
+	public final Charset charset() {
+		return cs;
+	}
+
+	/**
+	 * This is a facade method for encoding operation.
+	 * <p>
+	 * This method encodes the remaning character sequence of the given
+	 * character buffer into a new byte buffer. This method performs a complete
+	 * encoding operation, resets at first, then encodes, and flushes at last.
+	 * </p>
+	 * <p>
+	 * This method should not be invoked if another encode operation is ongoing.
+	 * </p>
+	 * 
+	 * @param in
+	 *            the input buffer
+	 * @return a new <code>ByteBuffer</code> containing the the bytes produced
+	 *         by this encoding operation. The buffer's limit will be the
+	 *         position of last byte in buffer, and the position will be zero
+	 * @throws IllegalStateException
+	 *             if another encoding operation is ongoing
+	 * @throws MalformedInputException
+	 *             if illegal input character sequence for this charset
+	 *             encountered, and the action for malformed error is
+	 *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}
+	 * @throws UnmappableCharacterException
+	 *             if legal but unmappable input character sequence for this
+	 *             charset encountered, and the action for unmappable character
+	 *             error is
+	 *             {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}.
+	 *             Unmappable means the Unicode character sequence at the input
+	 *             buffer's current postion cannot be mapped to a equivalent
+	 *             byte sequence.
+	 * @throws CharacterCodingException
+	 *             if other exception happened during the encode operation
+	 */
+	public final ByteBuffer encode(CharBuffer in)
+			throws CharacterCodingException {
+		if (in.remaining() == 0) {
+			return ByteBuffer.allocate(0);
+		}
+		reset();
+		int length = (int) (in.remaining() * averBytes);
+		ByteBuffer output = ByteBuffer.allocate(length);
+		CoderResult result = null;
+		while (true) {
+			result = encode(in, output, true);
+			if (!result.isOverflow()) {
+				break;
+			}
+			output = allocateMore(output);
+		}
+		while (flush(output) != CoderResult.UNDERFLOW) {
+			output = allocateMore(output);
+		}
+		output.flip();
+		if (result.isMalformed()) {
+			throw new MalformedInputException(result.length());
+		} else if (result.isUnmappable()) {
+			throw new UnmappableCharacterException(result.length());
+		}
+		return output;
+	}
+
+	// allocate more spaces to the given ByteBuffer
+	private ByteBuffer allocateMore(ByteBuffer output) {
+		if (output.capacity() == 0) {
+			return ByteBuffer.allocate(1);
+		}
+		ByteBuffer result = ByteBuffer.allocate(output.capacity() * 2);
+		output.flip();
+		result.put(output);
+		return result;
+	}
+
+	/**
+	 * Encodes characters starting at the current position of the given input
+	 * buffer, and writes the equivalent byte sequence into the given output
+	 * buffer from its current postion.
+	 * <p>
+	 * The buffers' position will be changed with the reading and writing
+	 * operation, but their limis and marks will be kept intact.
+	 * </p>
+	 * <p>
+	 * A <code>CoderResult</code> instance will be returned according to
+	 * following rules:
+	 * <ul>
+	 * <li>A {@link CoderResult#malformedForLength(int) malformed input} result
+	 * indicates that some malformed input error encountered, and the erroneous
+	 * characters start at the input buffer's postion and their number can be
+	 * got by result's {@link CoderResult#length() length}. This kind of result
+	 * can be returned only if the malformed action is
+	 * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li> <li>{@link CoderResult#UNDERFLOW CoderResult.UNDERFLOW}
+	 * indicates that as many characters as possible in the input buffer has
+	 * been encoded. If there is no further input and no characters left in the
+	 * input buffer then this task is complete. If this is not the case then the
+	 * client should call this method again supplying some more input
+	 * characters.</li> <li>{@link CoderResult#OVERFLOW CoderResult.OVERFLOW}
+	 * indicates that the output buffer has been filled, while there are still
+	 * some characters remaining in the input buffer. This method should be
+	 * invoked again with a non-full output buffer </li> <li>A
+	 * {@link CoderResult#unmappableForLength(int) unmappable character} result
+	 * indicates that some unmappable character error was encountered, and the
+	 * erroneous characters start at the input buffer's postion and their number
+	 * can be got by result's {@link CoderResult#length() length}. This kind of
+	 * result can be returned only on
+	 * {@link CodingErrorAction#REPORT CodingErrorAction.REPORT}. </li>
+	 * </ul>
+	 * </p>
+	 * <p>
+	 * The <code>endOfInput</code> parameter indicates that if the invoker can
+	 * provider further input. This parameter is true if and only if the
+	 * characters in current input buffer are all inputs for this encoding
+	 * operation. Note that it is common and won't cause error that the invoker
+	 * sets false and then finds no more input available; while it may cause
+	 * error that the invoker always sets true in several consecutive
+	 * invocations so that any remaining input will be treated as malformed
+	 * input.
+	 * </p>
+	 * <p>
+	 * This method invokes
+	 * {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop} method to
+	 * implement basic encode logic for specific charset.
+	 * </p>
+	 * 
+	 * @param in
+	 *            the input buffer
+	 * @param out
+	 *            the output buffer
+	 * @param endOfInput
+	 *            true if all the input characters have been provided
+	 * @return a <code>CoderResult</code> instance indicating the result
+	 * @throws IllegalStateException
+	 *             if the encoding operation has already started or no more
+	 *             input needed in this encoding progress.
+	 * @throws CoderMalfunctionError
+	 *             If the {@link #encodeLoop(CharBuffer, ByteBuffer) encodeLoop}
+	 *             method threw an <code>BufferUnderflowException</code> or
+	 *             <code>BufferUnderflowException</code>
+	 */
+	public final CoderResult encode(CharBuffer in, ByteBuffer out,
+			boolean endOfInput) {
+		if ((status == FLUSH) || (!endOfInput && status == END)) {
+			throw new IllegalStateException();
+		}
+		CoderResult result = CoderResult.UNDERFLOW;
+		if (in.remaining() > 0) {
+			while (true) {
+				CodingErrorAction action = null;                
+				result = encodeLoop(in, out);
+                int position = in.position();
+				if (endOfInput && result.isUnderflow() && in.hasRemaining()) {
+					result = CoderResult.malformedForLength(in.remaining());
+                    in.position(position + result.length());
+					action = malformAction;
+				} else if (result.isMalformed()) {
+					action = malformAction;
+				} else if (result.isUnmappable()) {
+					action = unmapAction;
+				}
+				if (action == CodingErrorAction.IGNORE) {
+					continue;
+				} else if (action == CodingErrorAction.REPLACE) {
+					out.put(replace);
+					continue;
+				}
+				break;
+			}
+		}
+		status = endOfInput ? END : ONGOING;
+		return result;
+	}
+
+	/**
+	 * Encode characters into bytes. This method is called by
+	 * {@link #encode(CharBuffer, ByteBuffer, boolean) encode}.
+	 * 
+	 * This method will implement the essential encoding operation, and it won't
+	 * stop encoding until either all the input characters are read, the output
+	 * buffer is filled, or some exception encountered. And then it will return
+	 * a <code>CoderResult</code> object indicating the result of current
+	 * encoding operation. The rules to construct the <code>CoderResult</code>
+	 * is same as the {@link #encode(CharBuffer, ByteBuffer, boolean) encode}.
+	 * When exception encountered in the encoding operation, most implementation
+	 * of this mehtod will return a relevant result object to
+	 * {@link #encode(CharBuffer, ByteBuffer, boolean) encode} method, and some
+	 * performance optimized implementation may handle the exception and
+	 * implement the error action itself.
+	 * 
+	 * The buffers are scanned from their current positions, and their postions
+	 * will be modified accordingly, while their marks and limits will be
+	 * intact. At most {@link CharBuffer#remaining() in.remaining()} characters
+	 * will be read, and {@link ByteBuffer#remaining() out.remaining()} bytes
+	 * will be written.
+	 * 
+	 * Note that some implementation may pre-scan the input buffer and return
+	 * <code>CoderResult.UNDERFLOW</code> until it receives sufficient input.
+	 * 
+	 * @param in
+	 *            the input buffer
+	 * @param out
+	 *            the output buffer
+	 * @return a <code>CoderResult</code> instance indicating the result
+	 */
+	protected abstract CoderResult encodeLoop(CharBuffer in, ByteBuffer out);
+
+	/**
+	 * Flush this encoder.
+	 * 
+	 * This method will call {@link #implFlush(ByteBuffer) implFlush}. Some
+	 * encoders may need to write some bytes to the output buffer when they have
+	 * read all input characters, subclasses can overridden
+	 * {@link #implFlush(ByteBuffer) implFlush} to perform writing action.
+	 * 
+	 * The maximum number of written bytes won't larger than
+	 * {@link ByteBuffer#remaining() out.remaining()}. If some encoder want to
+	 * write more bytes than output buffer's remaining spaces, then
+	 * <code>CoderResult.OVERFLOW</code> will be returned, and this method
+	 * must be called again with a byte buffer has more spaces. Otherwise this
+	 * method will return <code>CoderResult.UNDERFLOW</code>, which means one
+	 * encoding process has been completed sucessfully.
+	 * 
+	 * During the flush, the output buffer's position will be changed
+	 * accordingly, while its mark and limit will be intact.
+	 * 
+	 * @param out
+	 *            the given output buffer
+	 * @return <code>CoderResult.UNDERFLOW</code> or
+	 *         <code>CoderResult.OVERFLOW</code>
+	 * @throws IllegalStateException
+	 *             if this encoder hasn't read all input characters during one
+	 *             encoding process, which means neither after calling
+	 *             {@link #encode(CharBuffer) encode(CharBuffer)} nor after
+	 *             calling {@link #encode(CharBuffer, ByteBuffer, boolean) 
+	 *             encode(CharBuffer, ByteBuffer, boolean)} with true value for
+	 *             the last boolean parameter
+	 */
+	public final CoderResult flush(ByteBuffer out) {
+		if (status != END && status != INIT) {
+			throw new IllegalStateException();
+		}
+		CoderResult result = implFlush(out);
+		if (result == CoderResult.UNDERFLOW) {
+			status = FLUSH;
+		}
+		return result;
+	}
+
+	/**
+	 * Flush this encoder. Default implementaion does nothing and always return
+	 * <code>CoderResult.UNDERFLOW</code>, and this method can be overridden
+	 * if needed.
+	 * 
+	 * @param out
+	 *            the output buffer
+	 * @return <code>CoderResult.UNDERFLOW</code> or
+	 *         <code>CoderResult.OVERFLOW</code>
+	 */
+	protected CoderResult implFlush(ByteBuffer out) {
+		return CoderResult.UNDERFLOW;
+	}
+
+	/**
+	 * Notify that this encoder's <code>CodingErrorAction</code> specified for
+	 * malformed input error has been changed. Default implementaion does
+	 * nothing, and this method can be overridden if needed.
+	 * 
+	 * @param newAction
+	 *            The new action
+	 */
+	protected void implOnMalformedInput(CodingErrorAction newAction) {
+		// default implementation is empty
+	}
+
+	/**
+	 * Notify that this encoder's <code>CodingErrorAction</code> specified for
+	 * unmappable character error has been changed. Default implementaion does
+	 * nothing, and this method can be overridden if needed.
+	 * 
+	 * @param newAction
+	 *            The new action
+	 */
+	protected void implOnUnmappableCharacter(CodingErrorAction newAction) {
+		// default implementation is empty
+	}
+
+	/**
+	 * Notify that this encoder's replacement has been changed. Default
+	 * implementaion does nothing, and this method can be overridden if needed.
+	 * 
+	 * @param newReplacement
+	 *            the new replacement string
+	 */
+	protected void implReplaceWith(byte[] newReplacement) {
+		// default implementation is empty
+	}
+
+	/**
+	 * Reset this encoder's charset related state. Default implementaion does
+	 * nothing, and this method can be overridden if needed.
+	 */
+	protected void implReset() {
+		// default implementation is empty
+	}
+
+	/**
+	 * Check if the given argument is legal as this encoder's replacement byte
+	 * array.
+	 * 
+	 * The given byte array is legal if and only if it can be decode into
+	 * sixteen bits Unicode characters.
+	 * 
+	 * This method can be overriden for performance improvement.
+	 * 
+	 * @param repl
+	 *            the given byte array to be checked
+	 * @return true if the the given argument is legal as this encoder's
+	 *         replacement byte array.
+	 */
+	public boolean isLegalReplacement(byte[] repl) {
+		CodingErrorAction malform = decoder.malformedInputAction();
+		CodingErrorAction unmap = decoder.unmappableCharacterAction();
+		decoder.onMalformedInput(CodingErrorAction.REPORT);
+		decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
+		ByteBuffer in = ByteBuffer.wrap(repl);
+		CharBuffer out = CharBuffer.allocate((int) (repl.length * decoder
+				.maxCharsPerByte()));
+		CoderResult result = decoder.decode(in, out, true);
+		decoder.onMalformedInput(malform);
+		decoder.onUnmappableCharacter(unmap);
+		return !result.isError();
+	}
+
+	/**
+	 * Gets this encoder's <code>CodingErrorAction</code> when malformed input
+	 * occured during encoding process.
+	 * 
+	 * @return this encoder's <code>CodingErrorAction</code> when malformed
+	 *         input occured during encoding process.
+	 */
+	public CodingErrorAction malformedInputAction() {
+		return malformAction;
+	}
+
+	/**
+	 * Get the maximum number of bytes which can be created by this encoder for
+	 * one input character, must be positive
+	 * 
+	 * @return the maximum number of bytes which can be created by this encoder
+	 *         for one input character, must be positive
+	 */
+	public final float maxBytesPerChar() {
+		return maxBytes;
+	}
+
+	/**
+	 * Set this encoder's action on malformed input error.
+	 * 
+	 * This method will call the
+	 * {@link #implOnMalformedInput(CodingErrorAction) implOnMalformedInput}
+	 * method with the given new action as argument.
+	 * 
+	 * @param newAction
+	 *            the new action on malformed input error
+	 * @return this encoder
+	 * @throws IllegalArgumentException
+	 *             if the given newAction is null
+	 */
+	public final CharsetEncoder onMalformedInput(CodingErrorAction newAction) {
+		if (null == newAction) {
+			throw new IllegalArgumentException(
+					"Action on malformed input error cannot be null!"); //$NON-NLS-1$
+		}
+		malformAction = newAction;
+		implOnMalformedInput(newAction);
+		return this;
+	}
+
+	/**
+	 * Set this encoder's action on unmappable character error.
+	 * 
+	 * This method will call the
+	 * {@link #implOnUnmappableCharacter(CodingErrorAction) implOnUnmappableCharacter}
+	 * method with the given new action as argument.
+	 * 
+	 * @param newAction
+	 *            the new action on unmappable character error
+	 * @return this encoder
+	 * @throws IllegalArgumentException
+	 *             if the given newAction is null
+	 */
+	public final CharsetEncoder onUnmappableCharacter(
+			CodingErrorAction newAction) {
+		if (null == newAction) {
+			throw new IllegalArgumentException(
+					"Action on unmappable character error cannot be null!"); //$NON-NLS-1$
+		}
+		unmapAction = newAction;
+		implOnUnmappableCharacter(newAction);
+		return this;
+	}
+
+	/**
+	 * Get the replacement byte array, which is never null or empty, and it is
+	 * legal
+	 * 
+	 * @return the replacement byte array, cannot be null or empty, and it is
+	 *         legal
+	 */
+	public final byte[] replacement() {
+		return replace;
+	}
+
+	/**
+	 * Set new replacement value.
+	 * 
+	 * This method first checks the given replacement's validity, then changes
+	 * the replacement value, and at last calls
+	 * {@link #implReplaceWith(byte[]) implReplaceWith} method with the given
+	 * new replacement as argument.
+	 * 
+	 * @param replacement
+	 *            the replacement byte array, cannot be null or empty, its
+	 *            length cannot larger than <code>maxBytesPerChar</code>, and
+	 *            must be legal replacement, which can be justified by
+	 *            <code>isLegalReplacement(byte[] repl)</code>
+	 * @return this encoder
+	 * @throws IllegalArgumentException
+	 *             if the given replacement cannot satisfy the requirement
+	 *             metioned above
+	 */
+	public final CharsetEncoder replaceWith(byte[] replacement) {
+		if (null == replacement || 0 == replacement.length
+				|| maxBytes < replacement.length
+				|| !isLegalReplacement(replacement)) {
+			throw new IllegalArgumentException("Replacement is illegal"); //$NON-NLS-1$
+		}
+		replace = replacement;
+		implReplaceWith(replacement);
+		return this;
+	}
+
+	/**
+	 * Reset this encoder. This method will reset internla status, and then call
+	 * <code>implReset()</code> to reset any status related to specific
+	 * charset.
+	 * 
+	 * @return this encoder
+	 */
+	public final CharsetEncoder reset() {
+		status = INIT;
+		implReset();
+		return this;
+	}
+
+	/**
+	 * Gets this encoder's <code>CodingErrorAction</code> when unmappable
+	 * character occured during encoding process.
+	 * 
+	 * @return this encoder's <code>CodingErrorAction</code> when unmappable
+	 *         character occured during encoding process.
+	 */
+	public CodingErrorAction unmappableCharacterAction() {
+		return unmapAction;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderMalfunctionError.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderMalfunctionError.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderMalfunctionError.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderMalfunctionError.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,53 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Errors thrown when the encoder/decoder is malfunctioning.
+ * 
+ */
+public class CoderMalfunctionError extends Error {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * This constant is used during deserialization to check the J2SE version
+	 * which created the serialized object.
+	 */
+	static final long serialVersionUID = -1151412348057794301L; // J2SE 1.4.2
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructs an instance of this error.
+	 * 
+	 * @param ex
+	 *            the original exception thrown by the encoder/decoder
+	 */
+	public CoderMalfunctionError(Exception ex) {
+		super(ex);
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderResult.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderResult.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderResult.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CoderResult.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,315 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.util.WeakHashMap;
+
+/**
+ * Used to indicate the result of encoding/decoding. There are four types of
+ * results:
+ * <ol>
+ * <li>UNDERFLOW indicates all input has been processed, or more input is
+ * required. It is represented by the unique object
+ * <code>CoderResult.UNDERFLOW</code>.
+ * <li>OVERFLOW indicates insufficient output buffer. It is represented by the
+ * unique object <code>CoderResult.OVERFLOW</code>.
+ * <li>A malformed-input error indicates an unrecognizable sequence of input
+ * units has been encountered. Get an instance of this type of result by calling
+ * <code>CoderResult.malformedForLength(int)</code> with the length of the
+ * malformed-input.
+ * <li>An unmappable-charactor error indicates a sequence of input units can
+ * not be mapped to the output charset. Get an instance of this type of result
+ * by calling <code>CoderResult.unmappableForLength(int)</code> with the input
+ * sequence size indicating the identity of the unmappable character.
+ * </ol>
+ * 
+ */
+public class CoderResult {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	// indicating underflow error type
+	private static final int TYPE_UNDERFLOW = 1;
+
+	// indicating overflow error type
+	private static final int TYPE_OVERFLOW = 2;
+
+	// indicating malformed-input error type
+	private static final int TYPE_MALFORMED_INPUT = 3;
+
+	// indicating unmappable character error type
+	private static final int TYPE_UNMAPPABLE_CHAR = 4;
+
+	/**
+	 * Result object indicating that there is insufficient data in the
+	 * encoding/decoding buffer or that additional data is required.
+	 */
+	public static final CoderResult UNDERFLOW = new CoderResult(TYPE_UNDERFLOW,
+			0);
+
+	/**
+	 * Result object used to signify that the out buffer does not have enough
+	 * space available in it to store the result of the encoding/decoding.
+	 */
+	public static final CoderResult OVERFLOW = new CoderResult(TYPE_OVERFLOW, 0);
+
+	/*
+	 * --------------------------------------------------------------------
+	 * Class variables
+	 * --------------------------------------------------------------------
+	 */
+
+	// stores unique result objects for each malformed-input error of a certain
+	// length
+	private static WeakHashMap _malformedErrors = new WeakHashMap();
+
+	// stores unique result objects for each unmappable-character error of a
+	// certain length
+	private static WeakHashMap _unmappableErrors = new WeakHashMap();
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the type this result
+	private final int type;
+
+	// the length of the erroneous input
+	private final int length;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Construct a <code>CoderResult</code> object with its text description.
+	 * 
+	 * @param type
+	 *            the type of this result
+	 * @param length
+	 *            the length of the erroneous input
+	 */
+	private CoderResult(int type, int length) {
+		super();
+		this.type = type;
+		this.length = length;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets a <code>CoderResult</code> object indicating a malformed-input
+	 * error.
+	 * 
+	 * @param length
+	 *            the length of the malformed-input
+	 * @return a <code>CoderResult</code> object indicating a malformed-input
+	 *         error
+	 * @throws IllegalArgumentException
+	 *             If <code>length</code> is non-positive.
+	 */
+	public static synchronized CoderResult malformedForLength(int length)
+			throws IllegalArgumentException {
+		if (length > 0) {
+			synchronized (_malformedErrors) {
+				Integer key = new Integer(length);
+				CoderResult r = (CoderResult) _malformedErrors.get(key);
+				if (null == r) {
+					r = new CoderResult(TYPE_MALFORMED_INPUT, length);
+					_malformedErrors.put(key, r);
+				}
+				return r;
+			}
+		}
+		throw new IllegalArgumentException("The length must be positive."); //$NON-NLS-1$
+	}
+
+	/**
+	 * Gets a <code>CoderResult</code> object indicating an unmappable
+	 * character error.
+	 * 
+	 * @param length
+	 *            the length of the input unit sequence denoting the unmappable
+	 *            character
+	 * @return a <code>CoderResult</code> object indicating an unmappable
+	 *         character error
+	 * @throws IllegalArgumentException
+	 *             If <code>length</code> is non-positive.
+	 */
+	public static synchronized CoderResult unmappableForLength(int length)
+			throws IllegalArgumentException {
+		if (length > 0) {
+			synchronized (_unmappableErrors) {
+				Integer key = new Integer(length);
+				CoderResult r = (CoderResult) _unmappableErrors.get(key);
+				if (null == r) {
+					r = new CoderResult(TYPE_UNMAPPABLE_CHAR, length);
+					_unmappableErrors.put(key, r);
+				}
+				return r;
+			}
+		}
+		throw new IllegalArgumentException("The length must be positive."); //$NON-NLS-1$
+	}
+
+	/**
+	 * Answers true if this result is an underflow condition.
+	 * 
+	 * @return true if an underflow, otherwise false
+	 */
+	public boolean isUnderflow() {
+		return this.type == TYPE_UNDERFLOW;
+	}
+
+	/**
+	 * Answers true if this result represents a malformed-input error or an
+	 * unmappable-character error.
+	 * 
+	 * @return true if a malformed-input error or an unmappable-character error,
+	 *         otherwise false
+	 */
+	public boolean isError() {
+		return this.type == TYPE_MALFORMED_INPUT
+				|| this.type == TYPE_UNMAPPABLE_CHAR;
+	}
+
+	/**
+	 * Answers true if this result represents a malformed-input error.
+	 * 
+	 * @return true if a malformed-input error, otherwise false
+	 */
+	public boolean isMalformed() {
+		return this.type == TYPE_MALFORMED_INPUT;
+	}
+
+	/**
+	 * Answers true if this result is an overflow condition.
+	 * 
+	 * @return true if an overflow, otherwise false
+	 */
+	public boolean isOverflow() {
+		return this.type == TYPE_OVERFLOW;
+	}
+
+	/**
+	 * Answers true if this result represents an unmappable-character error.
+	 * 
+	 * @return true if an unmappable-character error, otherwise false
+	 */
+	public boolean isUnmappable() {
+		return this.type == TYPE_UNMAPPABLE_CHAR;
+	}
+
+	/**
+	 * Gets the length of the erroneous input. The length is only meaningful to
+	 * a malformed-input error or an unmappble character error.
+	 * 
+	 * @return the length, as an integer, of this object's erroneous input 
+	 * @throws UnsupportedOperationException
+	 *             If this result is an overflow or underflow.
+	 */
+	public int length() throws UnsupportedOperationException {
+		if (this.type == TYPE_MALFORMED_INPUT
+				|| this.type == TYPE_UNMAPPABLE_CHAR) {
+			return this.length;
+		}
+		throw new UnsupportedOperationException(
+				"The length of the erroneous input is only meaningful to a malformed-input error or an unmappble character error"); //$NON-NLS-1$
+	}
+
+	/**
+	 * Throws an exception corresponding to this coder result.
+	 * 
+	 * @throws BufferUnderflowException
+	 *             If an underflow.
+	 * @throws BufferOverflowException
+	 *             If an overflow.
+	 * @throws UnmappableCharacterException
+	 *             If an unmappable-character error.
+	 * @throws MalformedInputException
+	 *             If a malformed-input error.
+	 * @throws CharacterCodingException
+	 *             The default exception.
+	 */
+	public void throwException() throws BufferUnderflowException,
+			BufferOverflowException, UnmappableCharacterException,
+			MalformedInputException, CharacterCodingException {
+		switch (this.type) {
+		case TYPE_UNDERFLOW:
+			throw new BufferUnderflowException();
+		case TYPE_OVERFLOW:
+			throw new BufferOverflowException();
+		case TYPE_UNMAPPABLE_CHAR:
+			throw new UnmappableCharacterException(this.length);
+		case TYPE_MALFORMED_INPUT:
+			throw new MalformedInputException(this.length);
+		default:
+			throw new CharacterCodingException();
+		}
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods overriding parent class Object
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Returns a text description of this result.
+	 * 
+	 * @return a text description of this result
+	 */
+	public String toString() {
+		String dsc = null;
+		switch (this.type) {
+		case TYPE_UNDERFLOW:
+			dsc = "UNDERFLOW error"; //$NON-NLS-1$
+			break;
+		case TYPE_OVERFLOW:
+			dsc = "OVERFLOW error"; //$NON-NLS-1$
+			break;
+		case TYPE_UNMAPPABLE_CHAR:
+			dsc = "Unmappable-character error with erroneous input length " //$NON-NLS-1$
+					+ this.length;
+			break;
+		case TYPE_MALFORMED_INPUT:
+			dsc = "Malformed-input error with erroneous input length " //$NON-NLS-1$
+					+ this.length;
+			break;
+		default:
+			dsc = ""; //$NON-NLS-1$
+			break;
+		}
+		return "CoderResult[" + dsc + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CodingErrorAction.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CodingErrorAction.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CodingErrorAction.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/CodingErrorAction.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Used to indicate what kind of actions to take in case of encoding/decoding
+ * errors. Currently three actions are defined, namely, IGNORE, REPLACE and
+ * REPORT.
+ * 
+ */
+public class CodingErrorAction {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Indicating the action to ignore any errors.
+	 */
+	public static final CodingErrorAction IGNORE = new CodingErrorAction(
+			"IGNORE"); //$NON-NLS-1$
+
+	/**
+	 * Indicating the action to fill in the output with a replacement character
+	 * when malformed input or an unmappable character is encountered.
+	 */
+	public static final CodingErrorAction REPLACE = new CodingErrorAction(
+			"REPLACE"); //$NON-NLS-1$
+
+	/**
+	 * Indicating the action to report the encountered error in an appropriate
+	 * manner, for example, throw an exception or return an informative result.
+	 */
+	public static final CodingErrorAction REPORT = new CodingErrorAction(
+			"REPORT"); //$NON-NLS-1$
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the name of this action
+	private String action;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * Can't instantiate outside.
+	 */
+	private CodingErrorAction(String action) {
+		this.action = action;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods overriding parent class Object
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Returns a text description of this action indication..
+	 * 
+	 * @return a text description of this action indication.
+	 */
+	public String toString() {
+		return "Action: " + this.action; //$NON-NLS-1$
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/IllegalCharsetNameException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/IllegalCharsetNameException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/IllegalCharsetNameException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/IllegalCharsetNameException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,78 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Thrown when an illegal charset name is encountered.
+ * 
+ */
+public class IllegalCharsetNameException extends IllegalArgumentException {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * This constant is used during deserialization to check the J2SE version
+	 * which created the serialized object.
+	 */
+	static final long serialVersionUID = 1457525358470002989L; // J2SE 1.4.2
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the illegal charset name
+	private String charsetName;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructs an instance of this exception with the supplied charset name.
+	 * 
+	 * @param charset
+	 *            the encountered illegal charset name
+	 */
+	public IllegalCharsetNameException(String charset) {
+		super("The illegal charset name is \"" + charset + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
+		this.charsetName = charset;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets the encountered illegal charset name.
+	 * 
+	 * @return the encountered illegal charset name
+	 */
+	public String getCharsetName() {
+		return this.charsetName;
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/MalformedInputException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/MalformedInputException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/MalformedInputException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/MalformedInputException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,93 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Thrown when a malformed input is encountered, for example, a byte sequence is
+ * illegal for the given charset.
+ * 
+ */
+public class MalformedInputException extends CharacterCodingException {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * This constant is used during deserialization to check the J2SE version
+	 * which created the serialized object.
+	 */
+	static final long serialVersionUID = -3438823399834806194L; // J2SE 1.4.2
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the length of the malformed input
+	private int inputLength;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructs an instance of this exception.
+	 * 
+	 * @param length
+	 *            the length of the malformed input
+	 */
+	public MalformedInputException(int length) {
+		this.inputLength = length;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets the length of the malformed input.
+	 * 
+	 * @return the length of the malformed input
+	 */
+	public int getInputLength() {
+		return this.inputLength;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods overriding parent class Throwable
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets a message describing this exception.
+	 * 
+	 * @return a message describing this exception
+	 */
+	public String getMessage() {
+		return "Malformed input length is " + this.inputLength + "."; //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnmappableCharacterException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnmappableCharacterException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnmappableCharacterException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnmappableCharacterException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,93 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Thrown when an unmappable character for the given charset is encountered.
+ * 
+ * 
+ */
+public class UnmappableCharacterException extends CharacterCodingException {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * This constant is used during deserialization to check the J2SE version
+	 * which created the serialized object.
+	 */
+	static final long serialVersionUID = -7026962371537706123L; // J2SE 1.4.2
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the length of the unmappable character
+	private int inputLength;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructs an instance of this exception.
+	 * 
+	 * @param length
+	 *            the length of the unmappable character
+	 */
+	public UnmappableCharacterException(int length) {
+		this.inputLength = length;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets the length of the unmappable character.
+	 * 
+	 * @return the length of the unmappable character
+	 */
+	public int getInputLength() {
+		return this.inputLength;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods overriding parent class Throwable
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets a message describing this exception.
+	 * 
+	 * @return a message describing this exception
+	 */
+	public String getMessage() {
+		return "The unmappable character length is " + this.inputLength + "."; //$NON-NLS-1$ //$NON-NLS-2$
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnsupportedCharsetException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnsupportedCharsetException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnsupportedCharsetException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/UnsupportedCharsetException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,78 @@
+/* Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset;
+
+
+/**
+ * Thrown when an unsupported charset name is encountered.
+ * 
+ */
+public class UnsupportedCharsetException extends IllegalArgumentException {
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constants
+	 * -------------------------------------------------------------------
+	 */
+
+	/*
+	 * This constant is used during deserialization to check the J2SE version
+	 * which created the serialized object.
+	 */
+	static final long serialVersionUID = 1490765524727386367L; // J2SE 1.4.2
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Instance variables
+	 * -------------------------------------------------------------------
+	 */
+
+	// the unsupported charset name
+	private String charsetName;
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Constructors
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Constructs an instance of this exception with the supplied charset name.
+	 * 
+	 * @param charset
+	 *            the encountered unsupported charset name
+	 */
+	public UnsupportedCharsetException(String charset) {
+		super("The unsupported charset name is \"" + charset + "\"."); //$NON-NLS-1$ //$NON-NLS-2$
+		this.charsetName = charset;
+	}
+
+	/*
+	 * -------------------------------------------------------------------
+	 * Methods
+	 * -------------------------------------------------------------------
+	 */
+
+	/**
+	 * Gets the encountered unsupported charset name.
+	 * 
+	 * @return the encountered unsupported charset name
+	 */
+	public String getCharsetName() {
+		return this.charsetName;
+	}
+
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/spi/CharsetProvider.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/spi/CharsetProvider.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/spi/CharsetProvider.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio_char/src/java/nio/charset/spi/CharsetProvider.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,61 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.nio.charset.spi;
+
+import java.nio.charset.Charset;
+import java.util.Iterator;
+
+/**
+ * The service provider class for character sets.
+ * 
+ */
+public abstract class CharsetProvider {
+
+	// The permission required to construct a new provider.
+	private static final RuntimePermission CONSTRUCT_PERM = new RuntimePermission(
+			"charsetProvider"); //$NON-NLS-1$
+
+	/**
+	 * Constructor for subclassing with concrete types.
+	 * 
+	 * @throws SecurityException
+	 *             if there is a security manager installed that does not permit
+	 *             the runtime permission labelled "charsetProvider".
+	 */
+	protected CharsetProvider() {
+		SecurityManager securityManager = System.getSecurityManager();
+		if (securityManager != null)
+			securityManager.checkPermission(CONSTRUCT_PERM);
+	}
+
+	/**
+	 * Answers an iterator over all the available charsets.
+	 * 
+	 * @return the iterator.
+	 */
+	public abstract Iterator charsets();
+
+	/**
+	 * Answers the named charset.
+	 * <p>
+	 * If the charset is unavailable the method returns <code>null</code>.
+	 * 
+	 * @param charsetName
+	 *            the canonical or alias name of a character set.
+	 * @return the charset, or <code>null</code> if unavailable.
+	 */
+	public abstract Charset charsetForName(String charsetName);
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/META-INF/MANIFEST.MF?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/META-INF/MANIFEST.MF (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/META-INF/MANIFEST.MF Wed Nov 30 21:29:27 2005
@@ -0,0 +1,11 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Harmony Regex
+Bundle-SymbolicName: org.apache.harmony.regex
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Eclipse-JREBundle: true
+Import-Package: java.lang,
+ java.util
+Export-Package: java.util.regex
+Require-Bundle: org.apache.harmony.luni

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Matcher.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Matcher.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Matcher.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Matcher.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,283 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util.regex;
+
+/**
+ * Matcher is a class used to create matching engines based on a specific
+ * regular expression pattern and a specific input character sequence. Matcher
+ * objects are stateful and therefore not thread safe. A Matcher object is
+ * created by the Pattern.matcher() method. A Matcher object can be reused to
+ * search the same or different character sequence through the use of the
+ * reset() method.
+ * 
+ */
+public final class Matcher {
+	/**
+	 * The start() method returns the index of the first character in the
+	 * currently matched subsequence.
+	 * 
+	 * @return Returns the index of the first character in the currently matched
+	 *         subsequence.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 */
+	public int start() throws IllegalStateException {
+		return 0;
+	}
+
+	/**
+	 * The end() method returns the index of the character immediately after the
+	 * last in the currently matched subsequence.
+	 * 
+	 * @return Returns the index of the character immediately after the last in
+	 *         the currently matched subsequence.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 */
+	public int end() throws IllegalStateException {
+		return 0;
+	}
+
+	/**
+	 * The start(int) method returns the index of the first character in the
+	 * captured group identified by the groupId argument. Group 0 always refers
+	 * to the entire matched subsequence so calling start(0) is equivalent to
+	 * calling start() with no arguments. It is possible to match a pattern
+	 * without finding a match for one or more capture groups. In the case where
+	 * a capture group k has not been matched, a value of -1 will be returned
+	 * from start(k). start(0) will never return -1.
+	 * 
+	 * @param groupId
+	 *            The index of the capturing group.
+	 * @return The index of the first character in the captured group or -1 if
+	 *         the group was not captured.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 * @throws IndexOutOfBoundsException
+	 *             If the groupId is less than zero or greater than
+	 *             groupCount().
+	 */
+	public int start(int groupId) throws IllegalStateException,
+			IndexOutOfBoundsException {
+		return 0;
+	}
+
+	/**
+	 * The end(int) method returns the index of the character immediately
+	 * following the last in the captured group identified by the groupId
+	 * argument. Group 0 always refers to the entire matched subsequence so
+	 * calling end(0) is equivalent to calling end() with no arguments. It is
+	 * possible to match a pattern without finding a match for one or more
+	 * capture groups. In the case where a capture group k has not been matched,
+	 * a value of -1 will be returned from end(k). end(0) will never return -1.
+	 * 
+	 * @param groupId
+	 *            The index of the capturing group.
+	 * @return The index of the character immediately following the last in the
+	 *         captured group or -1 if the group was not captured.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 * @throws IndexOutOfBoundsException
+	 *             If the groupId is less than zero or greater than
+	 *             groupCount().
+	 */
+	public int end(int groupId) throws IllegalStateException,
+			IndexOutOfBoundsException {
+		return 0;
+	}
+
+	/**
+	 * The group() method returns a String containing a copy of the entire
+	 * matched subsequence (group 0).
+	 * 
+	 * @return A string containing a copy of the entire matched subsequence.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 */
+	public String group() throws IllegalStateException {
+		return null;
+	}
+
+	/**
+	 * Return a String containing a copy of the matched capturing group
+	 * identified by groupId. If the identified group was not captured, this
+	 * method returns null.
+	 * 
+	 * @param groupId
+	 *            The index of the capturing group.
+	 * @return A String containing a copy of the matched capturing group
+	 *         identified by groupId or null if the group was not captured.
+	 * @throws IllegalStateException
+	 *             If the previous call to find, matches or lookingAt failed to
+	 *             find a match.
+	 * @throws IndexOutOfBoundsException
+	 *             If the groupId is less than zero or greater than
+	 *             groupCount().
+	 */
+	public String group(int groupId) throws IllegalStateException,
+			IndexOutOfBoundsException {
+		return null;
+	}
+
+	/**
+	 * Return the number of capturing groups in the pattern.
+	 * 
+	 * @return The number of capturing groups in the pattern.
+	 */
+	public int groupCount() {
+		return 0;
+	}
+
+	/*
+	 * The reset() method resets the internal state of the Matcher object to
+	 * begin scanning at the beginning of the character sequence.
+	 * 
+	 * @return A reference to this Matcher.
+	 */
+	public Matcher reset() {
+		return null;
+	}
+
+	/*
+	 * This reset() method is similar to the reset method without arguments
+	 * except that it also replaces the input character sequence which should be
+	 * scanned by the matcher.
+	 * 
+	 * @param input A new character sequence to scan @return A reference to this
+	 * Matcher.
+	 */
+	public Matcher reset(CharSequence input) {
+		return null;
+	}
+
+	/**
+	 * The find() method matches the pattern against the character sequence
+	 * beginning at the character after the last match or at the beginning of
+	 * the sequence if called immediately after reset(). The method returns true
+	 * if and only if a match is found.
+	 * 
+	 * @return A boolean indicating if the pattern was matched.
+	 */
+	public boolean find() {
+		return false;
+	}
+
+	/**
+	 * This find() method is similar to the version without arguments except
+	 * that an implicit reset() is done and the matching is started at the given
+	 * character sequence index.
+	 * 
+	 * @param start
+	 *            The starting index
+	 * @return A boolean indicating if the pattern was matched.
+	 * @throws IndexOutOfBoundsException
+	 *             If the start index is negative or greater than the length of
+	 *             the string.
+	 */
+	public boolean find(int start) throws IndexOutOfBoundsException {
+		return false;
+	}
+
+	/**
+	 * This method attempts to match the pattern against the character sequence
+	 * starting at the beginning. If the pattern matches even a prefix of the
+	 * input character sequence, lookingAt() will return true. Otherwise it will
+	 * return false.
+	 * 
+	 * @return A boolean indicating if the pattern matches a prefix of the input
+	 *         character sequence.
+	 */
+	public boolean lookingAt() {
+		return false;
+	}
+
+	/**
+	 * This method is identical in function to the Pattern.matches() method. It
+	 * returns true if and only if the regular expression pattern matches the
+	 * entire input character sequence.
+	 * 
+	 * @return A boolean indicating if the pattern matches the entire input
+	 *         character sequence.
+	 */
+	public boolean matches() {
+		return false;
+	}
+
+	/**
+	 * Return a reference to the pattern used by this Matcher.
+	 * 
+	 * @return A reference to the pattern used by this Matcher.
+	 */
+	public Pattern pattern() {
+		return null;
+	}
+
+	/**
+	 * Replace all occurrences of character sequences which match the pattern
+	 * with the given replacement string. The replacement string may refer to
+	 * capturing groups using the syntax "$<group number>".
+	 * 
+	 * @param replacement
+	 *            A string to replace occurrences of character sequences
+	 *            matching the pattern.
+	 * @return A new string with replacements inserted
+	 */
+	public String replaceAll(String replacement) {
+		return null;
+	}
+
+	/**
+	 * This is very similar to replaceAll except only the first occurrence of a
+	 * sequence matching the pattern is replaced.
+	 * 
+	 * @param replacement
+	 *            A string to replace occurrences of character sequences
+	 *            matching the pattern.
+	 * @return A new string with replacements inserted
+	 */
+	public String replaceFirst(String replacement) {
+		return null;
+	}
+
+	/**
+	 * TODO: appendReplacement javadoc
+	 * 
+	 * @param sb
+	 * @param replacement
+	 * @return
+	 * @throws IllegalStateException
+	 * @throws IndexOutOfBoundsException
+	 */
+	public Matcher appendReplacement(StringBuffer sb, String replacement)
+			throws IllegalStateException, IndexOutOfBoundsException {
+		return null;
+	}
+
+	/**
+	 * TODO: appendTail(StringBuffer) javadoc
+	 * 
+	 * @param sb
+	 * @return
+	 */
+	public StringBuffer appendTail(StringBuffer sb) {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Pattern.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Pattern.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Pattern.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/Pattern.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,209 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util.regex;
+
+import java.io.Serializable;
+
+
+/**
+ * Pattern implements a compiler for regular expressions as defined by the J2SE
+ * specification. The regular expression syntax is largely similar to the syntax
+ * defined by Perl 5 but has both omissions and extensions. A formal and
+ * complete definition of the regular expression syntax is not provided by the
+ * J2SE speTBD (TODO)
+ * 
+ */
+public final class Pattern implements Serializable {
+	static final long serialVersionUID = 5073258162644648461L;
+
+	public static final int UNIX_LINES = 1;
+
+	public static final int CASE_INSENSITIVE = 2;
+
+	public static final int COMMENTS = 4;
+
+	public static final int MULTILINE = 8;
+
+	public static final int DOTALL = 32;
+
+	public static final int UNICODE_CASE = 64;
+
+	public static final int CANON_EQ = 128;
+
+	/**
+	 * Create a compiled pattern corresponding to the input regular expression
+	 * string. Default options are used. For a description of option settings,
+	 * including their defaults, see compile(String,int).
+	 * 
+	 * @param regex
+	 *            A regular expression string.
+	 * @return A compiled pattern
+	 * @throws PatternSyntaxException
+	 *             If the input regular expression does not match the required
+	 *             grammar.
+	 */
+	public static Pattern compile(String regex) throws PatternSyntaxException {
+		return null;
+	}
+
+	/**
+	 * Return a compiled pattern corresponding to the input regular expression
+	 * string.
+	 * 
+	 * The input <code>flags</code> is a mask of the following flags:
+	 * <dl>
+	 * <dt><code>UNIX_LINES</code> (0x0001)
+	 * <dd>Enables UNIX lines mode where only \n is recognized as a line
+	 * terminator. The default setting of this flag is <em>off</em> indicating
+	 * that all of the following character sequences are recognized as line
+	 * terminators: \n, \r, \r\n, NEL (\u0085), \u2028 and \u2029.
+	 * <dt><code>CASE_INSENSITIVE</code> (0x0002)
+	 * <dd>Directs matching to be done in a way that ignores differences in
+	 * case. If input character sequences are encoded in character sets other
+	 * than ASCII, then the UNICODE_CASE must also be set to enable Unicode case
+	 * detection.
+	 * <dt><code>UNICODE_CASE</code> (0x0040)
+	 * <dd>Enables Unicode case folding if used in conjuntion with the
+	 * <code>CASE_INSENSITIVE</code> flag. If <code>CASE_INSENSITIVE</code>
+	 * is not set, then this flag has no effect.
+	 * <dt><code>COMMENTS</code> (0x0004)
+	 * <dd>Directs the pattern compiler to ignore whitespace and comments in
+	 * the pattern. Whitespace consists of sequences including only these
+	 * characters: SP (\u0020), HT (\t or \u0009), LF (\n or ), VT (\u000b), FF
+	 * (\f or \u000c), and CR (\r or ). A comment is any sequence of characters
+	 * beginning with the "#" (\u0023) character and ending in a LF character.
+	 * <dt><code>MULTILINE</code> (0x0008)
+	 * <dd>Turns on multiple line mode for matching of character sequences. By
+	 * default, this mode is off so that the character "^" (\u005e) matches the
+	 * beginning of the entire input sequence and the character "$" (\u0024)
+	 * matches the end of the input character sequence. In multiple line mode,
+	 * the character "^" matches any character in the input sequence which
+	 * immediately follows a line terminator and the character "$" matches any
+	 * character in the input sequence which immediately precedes a line
+	 * terminator.
+	 * <dt><code>DOTALL</code> (0x0020)
+	 * <dd>Enables the DOT (".") character in regular expressions to match line
+	 * terminators. By default, line terminators are not matched by DOT.
+	 * <dt><code>CANON_EQ</code> (0x0080)
+	 * <dd>Enables matching of character sequences which are cacnonically
+	 * equivalent according to the Unicode standard. Canonical equivalence is
+	 * described here: http://www.unicode.org/reports/tr15/. By default,
+	 * canonical equivalence is not detected while matching.
+	 * </dl>
+	 * 
+	 * @param regex
+	 *            A regular expression string.
+	 * @param flags
+	 *            A set of flags to control the compilation of the pattern.
+	 * @return A compiled pattern
+	 * @throws PatternSyntaxException
+	 *             If the input regular expression does not match the required
+	 *             grammar.
+	 */
+	public static Pattern compile(String regex, int flags)
+			throws PatternSyntaxException {
+		return null;
+	}
+
+	/**
+	 * Return the mask of flags used to compile the pattern
+	 * 
+	 * @return A mask of flags used to compile the pattern.
+	 */
+	public int flags() {
+		return 0;
+	}
+
+	/**
+	 * Returns the pattern string passed to the compile method
+	 * 
+	 * @return A string representation of the pattern
+	 */
+	public String pattern() {
+		return null;
+	}
+
+	/**
+	 * Create a matcher for this pattern and a given input character sequence
+	 * 
+	 * @param input
+	 *            The input character sequence
+	 * @return A new matcher
+	 */
+	public Matcher matcher(CharSequence input) {
+		return null;
+	}
+
+	/**
+	 * A convenience method to test for a match of an input character sequence
+	 * against a regular expression string. The return value is true only if
+	 * there is a <em>complete</em> match between the regular expression
+	 * string and the input sequence. Partial matches that leave characters in
+	 * the input sequence unmatched will cause a return value of false.
+	 * 
+	 * @param regex
+	 *            A regular expression string
+	 * @param input
+	 *            A character sequence to match against
+	 * 
+	 * @return true iff the character sequence completely matches the given
+	 *         regular expression
+	 * 
+	 * @throws PatternSyntaxException
+	 * 
+	 */
+	public static boolean matches(String regex, CharSequence input)
+			throws PatternSyntaxException {
+		return false;
+	}
+
+	/**
+	 * Tokenize the input character sequence using the pattern to recognize
+	 * token separators
+	 * 
+	 * @param input
+	 *            The input character sequence
+	 * @return An array of string tokens
+	 */
+	public final String[] split(CharSequence input) {
+		return null;
+	}
+
+	/**
+	 * Split an input string using the pattern as a token separator.
+	 * 
+	 * @param input
+	 *            Input sequence to tokenize
+	 * @param limit
+	 *            If positive, the maximum number of tokens to return. If
+	 *            negative, an indefinite number of tokens are returned. If
+	 *            zero, an indefinite number of tokens are returned but trailing
+	 *            empty tokens are excluded.
+	 * @return A sequence of tokens split out of the input string.
+	 */
+	public String[] split(CharSequence input, int limit) {
+		return null;
+	}
+
+	/**
+	 * Return a textual representation of the pattern.
+	 * 
+	 * @return The regular expression string
+	 */
+	public String toString() {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/PatternSyntaxException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/PatternSyntaxException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/PatternSyntaxException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/regex/src/java/util/regex/PatternSyntaxException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,47 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.util.regex;
+
+import java.io.Serializable;
+
+
+/**
+ * TODO Type description
+ * 
+ */
+public class PatternSyntaxException extends IllegalArgumentException implements
+		Serializable {
+	static final long serialVersionUID = -3864639126226059218L;
+
+	public PatternSyntaxException(String desc, String regex, int index) {
+	}
+
+	public String getDescription() {
+		return null;
+	}
+
+	public int getIndex() {
+		return 0;
+	}
+
+	public String getPattern() {
+		return null;
+	}
+
+	public String getMessage() {
+		return null;
+	}
+}

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/META-INF/MANIFEST.MF?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/META-INF/MANIFEST.MF (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/META-INF/MANIFEST.MF Wed Nov 30 21:29:27 2005
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Harmony Security
+Bundle-SymbolicName: org.apache.harmony.security
+Bundle-Version: 1.0.0
+Bundle-ClassPath: .
+Eclipse-JREBundle: true
+Import-Package: java.io,
+ java.lang,
+ java.net,
+ java.util,
+ java.util.zip
+Export-Package: java.security,
+ java.security.acl,
+ java.security.cert,
+ java.security.interfaces,
+ java.security.spec,
+ javax.security.auth,
+ javax.security.auth.callback,
+ javax.security.auth.kerberos,
+ javax.security.auth.login,
+ javax.security.auth.spi,
+ javax.security.auth.x500,
+ javax.security.cert,
+ javax.security.sasl,
+ org.ietf.jgss
+Require-Bundle: org.apache.harmony.luni

Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AccessControlException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AccessControlException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AccessControlException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/security/src/java/security/AccessControlException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,69 @@
+/* Copyright 1998, 2002 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.security;
+
+
+/**
+ * This runtime exception is thrown when an access control check indicates that
+ * access should not be granted.
+ * 
+ */
+public class AccessControlException extends SecurityException {
+
+	static final long serialVersionUID = 5138225684096988535L;
+
+	/**
+	 * The permission object associated with the receiver.
+	 */
+	Permission perm;
+
+	/**
+	 * Constructs a new instance of this class with its walkback and message
+	 * filled in.
+	 * 
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 */
+	public AccessControlException(String detailMessage) {
+		super(detailMessage);
+	}
+
+	/**
+	 * Constructs a new instance of this class with its walkback, message and
+	 * associated permission all filled in.
+	 * 
+	 * 
+	 * @param detailMessage
+	 *            String The detail message for the exception.
+	 * @param perm
+	 *            Permission The failed permission.
+	 */
+	public AccessControlException(String detailMessage, Permission perm) {
+		super(detailMessage);
+		this.perm = perm;
+	}
+
+	/**
+	 * Answers the receiver's permission.
+	 * 
+	 * 
+	 * @return Permission the receiver's permission
+	 */
+	public Permission getPermission() {
+		return perm;
+	}
+}



Mime
View raw message