com.ibm.icu4jni.converters
Class ByteToCharConverterICU

java.lang.Object
  extended bysun.io.ByteToCharConverter
      extended bycom.ibm.icu4jni.converters.ByteToCharConverterICU
Direct Known Subclasses:
ByteToCharGB18030

public class ByteToCharConverterICU
extends sun.io.ByteToCharConverter


Field Summary
 
Fields inherited from class sun.io.ByteToCharConverter
badInputLength, byteOff, charOff, subChars, subMode
 
Constructor Summary
ByteToCharConverterICU(java.lang.String enc)
          Create an instance of ByteToCharConverterICU with the specified encoding.
 
Method Summary
 java.lang.Object clone()
          Makes a complete copy of the current object.
 int convert(byte[] input, int inOff, int inEnd, char[] output, int outOff, int outEnd)
          Conversion through the JNI interface for ICU.
static sun.io.ByteToCharConverter createConverter(java.lang.String enc)
          Creates an ICU Converter of the specified encoding
protected  void finalize()
          Releases the system resources by cleanly closing ICU converter opened
 int flush(char[] output, int outStart, int outEnd)
          Writes any remaining output to the output buffer and resets the converter to its initial state.
 int getBadInputLength()
          Returns the length, in bytes, of the input which caused a MalformedInputException.
 java.lang.String getCharacterEncoding()
          Return the character set id
 int getMaxCharsPerByte()
          Returns the maximum number of characters needed to convert a byte.
 char[] getSubChars()
          Returns the substitution characters as an array of chars
 void reset()
          Reset the state of the converter
 void setSubstitutionChars(char[] c)
          Sets the substitution characters to use when the converter is in substitution mode.
 void setSubstitutionMode(boolean doSub)
          Sets converter into substitution mode.
 
Methods inherited from class sun.io.ByteToCharConverter
convertAll, getConverter, getDefault, nextByteIndex, nextCharIndex, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteToCharConverterICU

public ByteToCharConverterICU(java.lang.String enc)
                       throws java.io.UnsupportedEncodingException
Create an instance of ByteToCharConverterICU with the specified encoding.

Parameters:
enc - representing encoding
Throws:
java.io.UnsupportedEncodingException - if the converter could not be opened
Status:
Stable ICU 2.4.
Method Detail

convert

public int convert(byte[] input,
                   int inOff,
                   int inEnd,
                   char[] output,
                   int outOff,
                   int outEnd)
            throws sun.io.ConversionBufferFullException,
                   sun.io.UnknownCharacterException,
                   sun.io.MalformedInputException,
                   java.lang.IllegalArgumentException
Conversion through the JNI interface for ICU. 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.

Parameters:
input - 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).
output - 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:
sun.io.MalformedInputException - if the input buffer contains any sequence of bytes that is illegal for the input character set.
sun.io.UnknownCharacterException - for any character that that cannot be converted to Unicode. Thrown only when converter is not in substitution mode.
sun.io.ConversionBufferFullException - if output array is filled prior to converting all the input.
java.lang.IllegalArgumentException - is thrown if any of the arrays passed are null
Status:
Stable ICU 2.4.

getCharacterEncoding

public final java.lang.String getCharacterEncoding()
Return the character set id

Status:
Stable ICU 2.4.

flush

public final int flush(char[] output,
                       int outStart,
                       int outEnd)
                throws java.lang.IllegalArgumentException,
                       sun.io.ConversionBufferFullException,
                       sun.io.MalformedInputException
Writes any remaining output to the output buffer and resets the converter to its initial state.

Parameters:
output - char array to receive flushed output.
outStart - start writing to output array at this offset.
outEnd - stop writing to output array at this offset (exclusive).
Throws:
sun.io.ConversionBufferFullException - if output array is filled before all the output can be flushed. flush will write what it can to the output buffer and remember its state. An additional call to flush with a new output buffer will conclude the operation.
java.lang.IllegalArgumentException
sun.io.MalformedInputException
Status:
Stable ICU 2.4.

setSubstitutionChars

public final void setSubstitutionChars(char[] c)
                                throws java.lang.IllegalArgumentException
Sets the substitution characters to use when the converter is in substitution mode. The given chars must not be longer than the value returned by getMaxCharsPerByte for this converter.

Parameters:
c - the substitution bytes
Throws:
java.lang.IllegalArgumentException - if given byte array is longer than the value returned by the method getMaxBytesPerChar or if the JNI interface has returned an error code
See Also:
setSubstitutionMode(boolean), getMaxCharsPerByte()
Status:
Stable ICU 2.4.

reset

public final void reset()
Reset the state of the converter

Status:
Stable ICU 2.4.

getMaxCharsPerByte

public final int getMaxCharsPerByte()
Returns the maximum number of characters needed to convert a byte. Useful for calculating the maximum output buffer size needed for a particular input buffer. Returns 2 since surrogate support is included

Returns:
maximum number of chars need for converting a char
Status:
Stable ICU 2.4.

setSubstitutionMode

public final void setSubstitutionMode(boolean doSub)
Sets converter into substitution mode. In substitution mode, the converter will replace untranslatable characters in the source encoding with the substitution character set by setSubstitionChars. When not in substitution mode, the converter will throw an UnknownCharacterException when it encounters untranslatable input.

Parameters:
doSub - if true, enable substitution mode.
See Also:
setSubstitutionChars(char[])
Status:
Stable ICU 2.4.

getBadInputLength

public final int getBadInputLength()
Returns the length, in bytes, of the input which caused a MalformedInputException. Always refers to the last MalformedInputException thrown by the converter. If none have ever been thrown, returns 0.

Status:
Stable ICU 2.4.

getSubChars

public final char[] getSubChars()
Returns the substitution characters as an array of chars

Status:
Stable ICU 2.4.

finalize

protected void finalize()
                 throws java.lang.Throwable
Releases the system resources by cleanly closing ICU converter opened

Throws:
java.lang.Throwable - exception thrown by super class' finalize method
Status:
Stable ICU 2.4.

createConverter

public static final sun.io.ByteToCharConverter createConverter(java.lang.String enc)
                                                        throws java.io.UnsupportedEncodingException
Creates an ICU Converter of the specified encoding

Parameters:
enc - string
Returns:
ByteToCharConverter object
Throws:
java.io.UnsupportedEncodingException
Status:
Stable ICU 2.4.

clone

public java.lang.Object clone()
Makes a complete copy of the current object.

Returns:
a copy of this object if data clone is a success, otherwise null
Status:
Stable ICU 2.4.