Class CharsetConverter


  • public class CharsetConverter
    extends java.lang.Object
    P4Java charset converter class
    • Constructor Summary

      Constructors 
      Constructor Description
      CharsetConverter​(java.nio.charset.Charset fromCharset, java.nio.charset.Charset toCharset)
      Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.
      CharsetConverter​(java.nio.charset.Charset fromCharset, java.nio.charset.Charset toCharset, boolean ignoreBOM)
      Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.nio.ByteBuffer convert​(java.nio.ByteBuffer from)
      Convert a byte buffer by decoding using the fromCharset and encoding using the toCharset.
      java.nio.ByteBuffer convert​(java.nio.CharBuffer from)
      Converts a char buffer to a byte buffer using the toCharset.
      java.lang.String getToCharsetName()
      Get charset name of to charset used to encode
      • Methods inherited from class java.lang.Object

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

      • CharsetConverter

        public CharsetConverter​(java.nio.charset.Charset fromCharset,
                                java.nio.charset.Charset toCharset,
                                boolean ignoreBOM)
        Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.
        Parameters:
        fromCharset - fromCharset
        toCharset - toCharset
        ignoreBOM - - true to ignore any byte order marks written by the UTF-16 charset and omit them from all return byte buffers
      • CharsetConverter

        public CharsetConverter​(java.nio.charset.Charset fromCharset,
                                java.nio.charset.Charset toCharset)
        Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.
        Parameters:
        fromCharset - fromCharset
        toCharset - toCharset
    • Method Detail

      • getToCharsetName

        public java.lang.String getToCharsetName()
        Get charset name of to charset used to encode
        Returns:
        - charset name
      • convert

        public java.nio.ByteBuffer convert​(java.nio.CharBuffer from)
                                    throws FileEncoderException
        Converts a char buffer to a byte buffer using the toCharset. This ignores any existing underflow since the characters to convert are already complete and known.
        Parameters:
        from - from
        Returns:
        - byte buffer, use Buffer.position() for starting array offset, Buffer.limit() for number of bytes to read, and ByteBuffer.array() for the byte[] itself.
        Throws:
        FileEncoderException - on error
      • convert

        public java.nio.ByteBuffer convert​(java.nio.ByteBuffer from)
                                    throws FileDecoderException,
                                           FileEncoderException
        Convert a byte buffer by decoding using the fromCharset and encoding using the toCharset. The byte buffer returned will have its position be the array offset to use and the limit be the length of bytes to read from the byte buffer's backing array.

        Any remaining bytes that couldn't be converted are stored locally until the next call to . The from buffer specified will be joined with the underflow from a previous call on subsequent calls to .

        Parameters:
        from - - byte buffer to convert
        Returns:
        - byte buffer, use Buffer.position() for starting array offset, Buffer.limit() for number of bytes to read, and ByteBuffer.array() for the byte[] itself.
        Throws:
        FileEncoderException - on error
        FileDecoderException - on error