com.ibm.icu4jni.charset
Class CharsetEncoderICU

java.lang.Object
  extended byjava.nio.charset.CharsetEncoder
      extended bycom.ibm.icu4jni.charset.CharsetEncoderICU

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


Constructor Summary
CharsetEncoderICU(java.nio.charset.Charset cs, long cHandle, byte[] replacement)
          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)
          Deprecated. ICU 3.4
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,
                         byte[] replacement)
Construcs a new encoder for the given charset

Parameters:
cs - for which the decoder is created
cHandle - the address of ICU converter
replacement - the substitution bytes
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

Parameters:
newReplacement - to replace the error chars with
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

Parameters:
newAction - action to be taken
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

Parameters:
newAction - action to be taken
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.

Parameters:
out - action to be taken
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

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()

Parameters:
in - buffer to decode
out - buffer to populate with decoded result
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

Parameters:
c - the character to be converted
Returns:
true if a character can be converted
Status:
Stable ICU 2.4.

canEncode

public boolean canEncode(int codepoint)
Deprecated. ICU 3.4

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;
	}
 }
 

Parameters:
codepoint - Unicode code point as int value
Returns:
true if a character can be converted
Note, ICU 3.4.
Status:
Obsolete. Will be removed in 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.