com.ibm.icu4jni.converters
Class CharToByteConverterICU

java.lang.Object
  |
  +--sun.io.CharToByteConverter
        |
        +--com.ibm.icu4jni.converters.CharToByteConverterICU
Direct Known Subclasses:
CharToByteGB18030

public class CharToByteConverterICU
extends sun.io.CharToByteConverter


Field Summary
 
Fields inherited from class sun.io.CharToByteConverter
badInputLength, byteOff, charOff, subBytes, subMode
 
Constructor Summary
CharToByteConverterICU(java.lang.String enc)
          Create an instance of CharToByteConverterICU with the specified encoding.
 
Method Summary
 boolean canConvert(char c)
          Ascertains if a given Unicode character can be converted to the target encoding
 boolean canConvert(int codeUnit)
          Ascertains if a given Unicode codeunit (32bit value for handling surrogates) can be converted to the target encoding.
 java.lang.Object clone()
          Makes a complete copy of the current object.
 int convert(char[] input, int inOff, int inEnd, byte[] output, int outOff, int outEnd)
          Conversion through the JNI interface for ICU.
static sun.io.CharToByteConverter 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(byte[] 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 chars, of the input which caused a MalformedInputException.
 java.lang.String getCharacterEncoding()
          Return the character set id
 int getMaxBytesPerChar()
          Returns the max number of bytes needed for converting a Unicode character to target encoding
 void reset()
          Reset the state of the converter
 void setSubstitutionBytes(byte[] c)
          Sets the substitution bytes
 void setSubstitutionMode(boolean doSub)
          Sets converter into substitution mode.
 
Methods inherited from class sun.io.CharToByteConverter
convertAll, convertAny, flushAny, getConverter, getDefault, nextByteIndex, nextCharIndex, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CharToByteConverterICU

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

Throws:
java.io.UnsupportedEncodingException - if the converter could not be opened
Method Detail

convert

public int convert(char[] input,
                   int inOff,
                   int inEnd,
                   byte[] 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 Unicode characters into an array of bytes in the target character encoding. This method allows a buffer by buffer conversion of a data stream. The state of the conversion is saved between calls to convert. 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 sun.io.CharToByteConverter
Parameters:
input - array containing Unicode characters to be converted.
inEnd - stop conversion at this offset in input array (exclusive).
output - byte array to receive conversion result.
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 chars that is illegal in Unicode (principally unpaired surrogates and ? or ?). After this exception is thrown, the method nextCharIndex can be called to obtain the index of the first invalid input character. The MalformedInputException can be queried for the length of the invalid input.
sun.io.UnknownCharacterException - for any character that that cannot be converted to the external character encoding. 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
Status:
Stable ICU 2.4.

flush

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

Specified by:
flush in class sun.io.CharToByteConverter
Parameters:
output - byte 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
Status:
Stable ICU 2.4.

getCharacterEncoding

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

Specified by:
getCharacterEncoding in class sun.io.CharToByteConverter
Status:
Stable ICU 2.4.

setSubstitutionBytes

public final void setSubstitutionBytes(byte[] c)
                                throws java.lang.IllegalArgumentException
Sets the substitution bytes

Overrides:
setSubstitutionBytes in class sun.io.CharToByteConverter
java.lang.IllegalArgumentException
Status:
Stable ICU 2.4.

reset

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

Specified by:
reset in class sun.io.CharToByteConverter
Status:
Stable ICU 2.4.

getMaxBytesPerChar

public final int getMaxBytesPerChar()
Returns the max number of bytes needed for converting a Unicode character to target encoding

Specified by:
getMaxBytesPerChar in class sun.io.CharToByteConverter
Returns:
maximum number of bytes as an int
Status:
Stable ICU 2.4.

canConvert

public boolean canConvert(char c)
Ascertains if a given Unicode character can be converted to the target encoding

Overrides:
canConvert in class sun.io.CharToByteConverter
Returns:
true if a character can be converted

canConvert

public boolean canConvert(int codeUnit)
Ascertains if a given Unicode codeunit (32bit value for handling surrogates) can be converted to the target encoding. If the caller wants to test if a surrogate pair can be converted to target encoding then the responsibility of assembling the int value lies with the caller. For assembling a codeunit the caller has to do something like: while(i
Returns:
true if a character can be converted

getBadInputLength

public final int getBadInputLength()
Returns the length, in chars, 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.

Overrides:
getBadInputLength in class sun.io.CharToByteConverter
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 setSubstitutionBytes. When not in substitution mode, the converter will throw an UnknownCharacterException when it encounters untranslatable input.

Overrides:
setSubstitutionMode in class sun.io.CharToByteConverter
Parameters:
doSub - if true, enable substitution mode.
See Also:
setSubstitutionBytes(byte[])
Status:
Stable ICU 2.4.

finalize

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

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

createConverter

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

Returns:
CharToByteConverter object
java.io.UnsupportedEncodingException
Status:
Stable ICU 2.4.

clone

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

Overrides:
clone in class java.lang.Object
Returns:
a copy of this object if data clone is a success, otherwise null
Status:
Stable ICU 2.4.