Class CharsetEncoderICU

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) java.nio.charset.CoderResult cbFromUWriteSub​(CharsetEncoderICU encoder, java.nio.CharBuffer source, java.nio.ByteBuffer target, java.nio.IntBuffer offsets)  
      (package private) java.nio.charset.CoderResult cbFromUWriteUChars​(CharsetEncoderICU encoder, java.nio.CharBuffer source, java.nio.ByteBuffer target, java.nio.IntBuffer offsets)  
      (package private) java.nio.charset.CoderResult encode​(java.nio.CharBuffer source, java.nio.ByteBuffer target, java.nio.IntBuffer offsets, boolean flush)  
      protected java.nio.charset.CoderResult encodeLoop​(java.nio.CharBuffer in, java.nio.ByteBuffer out)
      Encodes one or more chars.
      (package private) abstract java.nio.charset.CoderResult encodeLoop​(java.nio.CharBuffer source, java.nio.ByteBuffer target, java.nio.IntBuffer offsets, boolean flush)  
      (package private) int fromUCountPending()  
      private void fromUnicodeReset()  
      (package private) java.nio.charset.CoderResult fromUnicodeWithCallback​(java.nio.CharBuffer source, java.nio.ByteBuffer target, java.nio.IntBuffer offsets, boolean flush)  
      (package private) static java.nio.charset.CoderResult fromUWriteBytes​(CharsetEncoderICU cnv, byte[] bytesArray, int bytesBegin, int bytesLength, java.nio.ByteBuffer out, java.nio.IntBuffer offsets, int sourceIndex)  
      private static CharsetCallback.Encoder getCallback​(java.nio.charset.CodingErrorAction action)  
      static int getMaxBytesForString​(int length, int maxCharSize)
      Calculates the size of a buffer for conversion from Unicode to a charset.
      (package private) java.nio.charset.CoderResult handleSurrogates​(char[] sourceArray, int sourceIndex, int sourceLimit, char lead)
      Same as handleSurrogates(CharBuffer, char), but with arrays.
      (package private) java.nio.charset.CoderResult handleSurrogates​(java.nio.CharBuffer source, char lead)
      Handles a common situation where a character has been read and it may be a lead surrogate followed by a trail surrogate.
      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 implReset()
      Resets the from Unicode mode of converter
      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.
      (package private) static boolean isFromUUseFallback​(boolean iUseFallback, int c)
      Use fallbacks from Unicode to codepage when useFallback or for private-use code points
      (package private) boolean isFromUUseFallback​(int c)  
      boolean isLegalReplacement​(byte[] repl)
      Overrides super class method
      private static boolean isUnicodePrivateUse​(int c)  
      float maxCharsPerByte()
      Returns the maxCharsPerByte value for the Charset that created this encoder.
      void setFallbackUsed​(boolean usesFallback)
      Sets whether this Encoder can use fallbacks?
      void setFromUCallback​(java.nio.charset.CoderResult err, CharsetCallback.Encoder newCallback, java.lang.Object newContext)
      Sets the callback encoder method and context to be used if an illegal sequence is encountered.
      void setFromUContext​(java.lang.Object newContext)
      Sets fromUContext used in callbacks.
      private void setSourcePosition​(java.nio.CharBuffer source)  
      • Methods inherited from class java.nio.charset.CharsetEncoder

        averageBytesPerChar, canEncode, canEncode, charset, encode, encode, flush, implReplaceWith, malformedInputAction, maxBytesPerChar, onMalformedInput, onUnmappableCharacter, replacement, replaceWith, reset, unmappableCharacterAction
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • errorBuffer

        byte[] errorBuffer
      • errorBufferLength

        int errorBufferLength
      • fromUnicodeStatus

        int fromUnicodeStatus
        these are for encodeLoopICU
      • fromUChar32

        int fromUChar32
      • useSubChar1

        boolean useSubChar1
      • useFallback

        boolean useFallback
      • preFromUFirstCP

        int preFromUFirstCP
      • preFromUArray

        char[] preFromUArray
      • preFromUBegin

        int preFromUBegin
      • preFromULength

        int preFromULength
      • invalidUCharBuffer

        char[] invalidUCharBuffer
      • invalidUCharLength

        int invalidUCharLength
      • fromUContext

        java.lang.Object fromUContext
      • EMPTY

        private static final java.nio.CharBuffer EMPTY
    • Constructor Detail

      • CharsetEncoderICU

        CharsetEncoderICU​(CharsetICU cs,
                          byte[] replacement)
    • Method Detail

      • 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.
      • isFromUUseFallback

        final boolean isFromUUseFallback​(int c)
      • isFromUUseFallback

        static final boolean isFromUUseFallback​(boolean iUseFallback,
                                                int c)
        Use fallbacks from Unicode to codepage when useFallback or for private-use code points
      • isUnicodePrivateUse

        private static final boolean isUnicodePrivateUse​(int c)
      • 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
        Parameters:
        newAction - action to be taken
        Throws:
        java.lang.IllegalArgumentException
      • 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
        Parameters:
        newAction - action to be taken
        Throws:
        java.lang.IllegalArgumentException
      • setFromUCallback

        public final void setFromUCallback​(java.nio.charset.CoderResult err,
                                           CharsetCallback.Encoder newCallback,
                                           java.lang.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​(java.lang.Object newContext)
        Sets fromUContext used in callbacks.
        Parameters:
        newContext - Object
        Throws:
        java.lang.IllegalArgumentException - The object is an illegal argument for UContext.
      • 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
        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 java.nio.charset.CharsetEncoder
      • fromUnicodeReset

        private void fromUnicodeReset()
      • 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
        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.
      • encodeLoop

        abstract java.nio.charset.CoderResult encodeLoop​(java.nio.CharBuffer source,
                                                         java.nio.ByteBuffer target,
                                                         java.nio.IntBuffer offsets,
                                                         boolean flush)
      • encode

        final java.nio.charset.CoderResult encode​(java.nio.CharBuffer source,
                                                  java.nio.ByteBuffer target,
                                                  java.nio.IntBuffer offsets,
                                                  boolean flush)
      • fromUnicodeWithCallback

        final java.nio.charset.CoderResult fromUnicodeWithCallback​(java.nio.CharBuffer source,
                                                                   java.nio.ByteBuffer target,
                                                                   java.nio.IntBuffer offsets,
                                                                   boolean flush)
      • isLegalReplacement

        public boolean isLegalReplacement​(byte[] repl)
        Overrides super class method
        Overrides:
        isLegalReplacement in class java.nio.charset.CharsetEncoder
      • fromUWriteBytes

        static final java.nio.charset.CoderResult fromUWriteBytes​(CharsetEncoderICU cnv,
                                                                  byte[] bytesArray,
                                                                  int bytesBegin,
                                                                  int bytesLength,
                                                                  java.nio.ByteBuffer out,
                                                                  java.nio.IntBuffer offsets,
                                                                  int sourceIndex)
      • fromUCountPending

        int fromUCountPending()
      • setSourcePosition

        private final void setSourcePosition​(java.nio.CharBuffer source)
        Parameters:
        source -
      • cbFromUWriteSub

        java.nio.charset.CoderResult cbFromUWriteSub​(CharsetEncoderICU encoder,
                                                     java.nio.CharBuffer source,
                                                     java.nio.ByteBuffer target,
                                                     java.nio.IntBuffer offsets)
      • cbFromUWriteUChars

        java.nio.charset.CoderResult cbFromUWriteUChars​(CharsetEncoderICU encoder,
                                                        java.nio.CharBuffer source,
                                                        java.nio.ByteBuffer target,
                                                        java.nio.IntBuffer offsets)
      • handleSurrogates

        final java.nio.charset.CoderResult handleSurrogates​(java.nio.CharBuffer source,
                                                            char lead)

        Handles a common situation where a character has been read and it may be a lead surrogate followed by a trail surrogate. This method can change the source position and will modify fromUChar32.

        If null is returned, then there was success in reading a surrogate pair, the codepoint is stored in fromUChar32 and fromUChar32 should be reset (to 0) after being read.

        Parameters:
        source - The encoding source.
        lead - A character that may be the first in a surrogate pair.
        Returns:
        CoderResult.malformedForLength(1) or CoderResult.UNDERFLOW if there is a problem, or null if there isn't.
        See Also:
        handleSurrogates(CharBuffer, char), handleSurrogates(char[], int, int, char)
      • handleSurrogates

        final java.nio.charset.CoderResult handleSurrogates​(char[] sourceArray,
                                                            int sourceIndex,
                                                            int sourceLimit,
                                                            char lead)

        Same as handleSurrogates(CharBuffer, char), but with arrays. As an added requirement, the calling method must also increment the index if this method returns null.

        Parameters:
        source - The encoding source.
        lead - A character that may be the first in a surrogate pair.
        Returns:
        CoderResult.malformedForLength(1) or CoderResult.UNDERFLOW if there is a problem, or null if there isn't.
        See Also:
        handleSurrogates(CharBuffer, char), handleSurrogates(char[], int, int, char)
      • 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