sun.io
Class ByteToCharUnicode

java.lang.Object
  extended by sun.io.ByteToCharConverter
      extended by sun.io.ByteToCharUnicode
Direct Known Subclasses:
ByteToCharUnicodeBig, ByteToCharUnicodeBigUnmarked, ByteToCharUnicodeLittle, ByteToCharUnicodeLittleUnmarked, ByteToCharUTF16

public class ByteToCharUnicode
extends ByteToCharConverter

Convert byte arrays containing Unicode characters into arrays of actual Unicode characters. This class may be used directly, in which case it expects the input byte array to begin with a byte-order mark, or it may be subclassed in order to preset the byte order and mark behavior.

Whether or not a mark is expected, if a mark that does not match the established byte order is later discovered then a MalformedInputException will be thrown by the convert method. If a correct mark is seen later in the input stream, it is passed through as a character.

See Also:
ByteToCharUnicodeLittle, ByteToCharUnicodeLittleUnmarked, ByteToCharUnicodeBig, ByteToCharUnicodeBigUnmarked

Field Summary
 
Fields inherited from class sun.io.ByteToCharConverter
badInputLength, byteOff, charOff, subChars, subMode
 
Constructor Summary
  ByteToCharUnicode()
          Creates a Unicode byte-to-char converter that expects the first pair of input bytes to be a byte-order mark, which will be interpreted and discarded.
protected ByteToCharUnicode(int bo, boolean m)
          Creates a Unicode byte-to-char converter that uses the given byte order and may or may not insist upon an initial byte-order mark.
 
Method Summary
 int convert(byte[] in, int inOff, int inEnd, char[] out, int outOff, int outEnd)
          Converts an array of bytes containing characters in an external encoding into an array of Unicode characters.
 int flush(char[] buf, int off, int len)
          Writes any remaining output to the output buffer and resets the converter to its initial state.
 String getCharacterEncoding()
          Returns the character set id for the conversion
 void reset()
          Resets converter to its initial state.
 
Methods inherited from class sun.io.ByteToCharConverter
convertAll, getBadInputLength, getConverter, getDefault, getMaxCharsPerByte, nextByteIndex, nextCharIndex, setSubstitutionChars, setSubstitutionMode, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteToCharUnicode

public ByteToCharUnicode()
Creates a Unicode byte-to-char converter that expects the first pair of input bytes to be a byte-order mark, which will be interpreted and discarded. If the first pair of bytes is not such a mark then a MalformedInputException will be thrown by the convert method.


ByteToCharUnicode

protected ByteToCharUnicode(int bo,
                            boolean m)
Creates a Unicode byte-to-char converter that uses the given byte order and may or may not insist upon an initial byte-order mark.

Method Detail

getCharacterEncoding

public String getCharacterEncoding()
Description copied from class: ByteToCharConverter
Returns the character set id for the conversion

Specified by:
getCharacterEncoding in class ByteToCharConverter

convert

public int convert(byte[] in,
                   int inOff,
                   int inEnd,
                   char[] out,
                   int outOff,
                   int outEnd)
            throws ConversionBufferFullException,
                   MalformedInputException
Description copied from class: ByteToCharConverter
Converts an array of bytes containing characters in an external encoding into an array of Unicode characters. This method allows a buffer by buffer conversion of a data stream. The state of the conversion is saved between calls to convert. Among other things, this means multibyte input sequences can be split between calls. If a call to convert results in an exception, the conversion may be continued by calling convert again with suitably modified parameters. All conversions should be finished with a call to the flush method.

Specified by:
convert in class ByteToCharConverter
Parameters:
in - byte array containing text to be converted.
inOff - begin conversion at this offset in input array.
inEnd - stop conversion at this offset in input array (exclusive).
out - character array to receive conversion result.
outOff - start writing to output array at this offset.
outEnd - stop writing to output array at this offset (exclusive).
Returns:
the number of bytes written to output.
Throws:
ConversionBufferFullException - if output array is filled prior to converting all the input.
MalformedInputException - if the input buffer contains any sequence of bytes that is illegal for the input character set.

reset

public void reset()
Description copied from class: ByteToCharConverter
Resets converter to its initial state.

Specified by:
reset in class ByteToCharConverter

flush

public int flush(char[] buf,
                 int off,
                 int len)
          throws MalformedInputException
Description copied from class: ByteToCharConverter
Writes any remaining output to the output buffer and resets the converter to its initial state.

Specified by:
flush in class ByteToCharConverter
Parameters:
buf - char array to receive flushed output.
off - start writing to output array at this offset.
len - stop writing to output array at this offset (exclusive).
Throws:
MalformedInputException - if the output to be flushed contained a partial or invalid multibyte character sequence. flush will write what it can to the output buffer and reset the converter before throwing this exception. An additional call to flush is not required.