Class CharsetConverter

java.lang.Object
com.perforce.p4java.CharsetConverter

public class CharsetConverter extends Object
P4Java charset converter class
  • Constructor Details

    • CharsetConverter

      public CharsetConverter(Charset fromCharset, 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(Charset fromCharset, 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 Details

    • getToCharsetName

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

      public ByteBuffer convert(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

      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