Class CharsetEncoderICU

java.lang.Object
java.nio.charset.CharsetEncoder
com.ibm.icu.charset.CharsetEncoderICU

public abstract class CharsetEncoderICU extends CharsetEncoder
An abstract class that provides framework methods of decoding operations for concrete subclasses. In the future this class will contain API that will implement converter semantics of ICU4C.
  • Method Details

    • isFallbackUsed

      public boolean isFallbackUsed()
      Is this Encoder allowed to use fallbacks? A fallback mapping is a mapping that will convert a Unicode codepoint sequence to a byte sequence, but the encoded byte sequence will round trip convert to a different Unicode codepoint sequence.
      Returns:
      true if the converter uses fallback, false otherwise.
    • setFallbackUsed

      public void setFallbackUsed(boolean usesFallback)
      Sets whether this Encoder can use fallbacks?
      Parameters:
      usesFallback - true if the user wants the converter to take advantage of the fallback mapping, false otherwise.
    • implOnMalformedInput

      protected void implOnMalformedInput(CodingErrorAction newAction)
      Sets the action to be taken if an illegal sequence is encountered
      Overrides:
      implOnMalformedInput in class CharsetEncoder
      Parameters:
      newAction - action to be taken
      Throws:
      IllegalArgumentException
    • implOnUnmappableCharacter

      protected void implOnUnmappableCharacter(CodingErrorAction newAction)
      Sets the action to be taken if an illegal sequence is encountered
      Overrides:
      implOnUnmappableCharacter in class CharsetEncoder
      Parameters:
      newAction - action to be taken
      Throws:
      IllegalArgumentException
    • setFromUCallback

      public final void setFromUCallback(CoderResult err, CharsetCallback.Encoder newCallback, Object newContext)
      Sets the callback encoder method and context to be used if an illegal sequence is encountered. You would normally call this twice to set both the malform and unmappable error. In this case, newContext should remain the same since using a different newContext each time will negate the last one used.
      Parameters:
      err - CoderResult
      newCallback - CharsetCallback.Encoder
      newContext - Object
    • setFromUContext

      public final void setFromUContext(Object newContext)
      Sets fromUContext used in callbacks.
      Parameters:
      newContext - Object
      Throws:
      IllegalArgumentException - The object is an illegal argument for UContext.
    • implFlush

      protected CoderResult implFlush(ByteBuffer out)
      Flushes any characters saved in the converter's internal buffer and resets the converter.
      Overrides:
      implFlush in class CharsetEncoder
      Parameters:
      out - action to be taken
      Returns:
      result of flushing action and completes the decoding all input. Returns CoderResult.UNDERFLOW if the action succeeds.
    • implReset

      protected void implReset()
      Resets the from Unicode mode of converter
      Overrides:
      implReset in class CharsetEncoder
    • encodeLoop

      protected CoderResult encodeLoop(CharBuffer in, 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 CharsetEncoder
      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.
    • isLegalReplacement

      public boolean isLegalReplacement(byte[] repl)
      Overrides super class method
      Overrides:
      isLegalReplacement in class CharsetEncoder
    • maxCharsPerByte

      public final float maxCharsPerByte()
      Returns the maxCharsPerByte value for the Charset that created this encoder.
      Returns:
      maxCharsPerByte
    • getMaxBytesForString

      public static int getMaxBytesForString(int length, int maxCharSize)
      Calculates the size of a buffer for conversion from Unicode to a charset. The calculated size is guaranteed to be sufficient for this conversion. It takes into account initial and final non-character bytes that are output by some converters. It does not take into account callbacks which output more than one charset character sequence per call, like escape callbacks. The default (substitution) callback only outputs one charset character sequence.
      Parameters:
      length - Number of chars to be converted.
      maxCharSize - Return value from maxBytesPerChar for the converter that will be used.
      Returns:
      Size of a buffer that will be large enough to hold the output of bytes