com.ibm.icu4jni.charset
Class CharsetEncoderICU

java.lang.Object
  |
  +--java.nio.charset.CharsetEncoder
        |
        +--com.ibm.icu4jni.charset.CharsetEncoderICU

public final class CharsetEncoderICU
extends java.nio.charset.CharsetEncoder


Constructor Summary
CharsetEncoderICU(java.nio.charset.Charset cs, long cHandle)
          Construcs a new encoder for the given charset
 
Method Summary
 boolean canEncode(char c)
          Ascertains if a given Unicode character can be converted to the target encoding
 boolean canEncode(int codepoint)
          Ascertains if a given Unicode code point (32bit value for handling surrogates) can be converted to the target encoding.
protected  java.nio.charset.CoderResult encodeLoop(java.nio.CharBuffer in, java.nio.ByteBuffer out)
          Encodes one or more chars.
protected  void finalize()
          Releases the system resources by cleanly closing ICU converter opened
protected  java.nio.charset.CoderResult implFlush(java.nio.ByteBuffer out)
          Flushes any characters saved in the converter's internal buffer and resets the converter.
protected  void implOnMalformedInput(java.nio.charset.CodingErrorAction newAction)
          Sets the action to be taken if an illegal sequence is encountered
protected  void implOnUnmappableCharacter(java.nio.charset.CodingErrorAction newAction)
          Sets the action to be taken if an illegal sequence is encountered
protected  void implReplaceWith(byte[] newReplacement)
          Sets this encoders replacement string.
protected  void implReset()
          Resets the from Unicode mode of converter
 
Methods inherited from class java.nio.charset.CharsetEncoder
averageBytesPerChar, canEncode, charset, encode, encode, flush, isLegalReplacement, malformedInputAction, maxBytesPerChar, onMalformedInput, onUnmappableCharacter, replacement, replaceWith, reset, unmappableCharacterAction
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharsetEncoderICU

public CharsetEncoderICU(java.nio.charset.Charset cs,
                         long cHandle)
Construcs a new encoder for the given charset

Parameters:
cHandle - the address of ICU converter
Status:
Stable ICU 2.4.
Method Detail

implReplaceWith

protected void implReplaceWith(byte[] newReplacement)
Sets this encoders replacement string. Substitutes the string in output if an umappable or illegal sequence is encountered

Overrides:
implReplaceWith in class java.nio.charset.CharsetEncoder
Status:
Stable ICU 2.4.

implOnMalformedInput

protected void implOnMalformedInput(java.nio.charset.CodingErrorAction newAction)
Sets the action to be taken if an illegal sequence is encountered

Overrides:
implOnMalformedInput in class java.nio.charset.CharsetEncoder
Throws:
java.lang.IllegalArgumentException
Status:
Stable ICU 2.4.

implOnUnmappableCharacter

protected void implOnUnmappableCharacter(java.nio.charset.CodingErrorAction newAction)
Sets the action to be taken if an illegal sequence is encountered

Overrides:
implOnUnmappableCharacter in class java.nio.charset.CharsetEncoder
Throws:
java.lang.IllegalArgumentException
Status:
Stable ICU 2.4.

implFlush

protected java.nio.charset.CoderResult implFlush(java.nio.ByteBuffer out)
Flushes any characters saved in the converter's internal buffer and resets the converter.

Overrides:
implFlush in class java.nio.charset.CharsetEncoder
Returns:
result of flushing action and completes the decoding all input. Returns CoderResult.UNDERFLOW if the action succeeds.
Status:
Stable ICU 2.4.

implReset

protected void implReset()
Resets the from Unicode mode of converter

Overrides:
implReset in class java.nio.charset.CharsetEncoder
Status:
Stable ICU 2.4.

encodeLoop

protected java.nio.charset.CoderResult encodeLoop(java.nio.CharBuffer in,
                                                  java.nio.ByteBuffer out)
Encodes one or more chars. The default behaviour of the converter is stop and report if an error in input stream is encountered. To set different behaviour use @see CharsetEncoder.onMalformedInput()

Specified by:
encodeLoop in class java.nio.charset.CharsetEncoder
Returns:
result of decoding action. Returns CoderResult.UNDERFLOW if the decoding action succeeds or more input is needed for completing the decoding action.
Status:
Stable ICU 2.4.

canEncode

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

Overrides:
canEncode in class java.nio.charset.CharsetEncoder
Returns:
true if a character can be converted
Status:
Stable ICU 2.4.

canEncode

public boolean canEncode(int codepoint)
Ascertains if a given Unicode code point (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 code point the caller can use UTF16 class of ICU4J and do something like:
 while(i
 or
 
 String src = new String(mySource);
 int i,codepoint;
 boolean passed = false;
 while(i0xfff)? 2:1;
	if(!(CharsetEncoderICU) myConv).canEncode(codepoint)){
	    passed = false;
	}
 }
 

Returns:
true if a character can be converted
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.