com.perforce.p4java
Class CharsetConverter

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

public class CharsetConverter
extends Object

P4Java charset converter class


Constructor Summary
CharsetConverter(Charset fromCharset, Charset toCharset)
          Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.
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.
 
Method Summary
 byte[] clearUnderflow()
          Get and clear the current converted underflow byte array.
 ByteBuffer convert(ByteBuffer from)
          Convert a byte buffer by decoding using the fromCharset and encoding using the toCharset.
 ByteBuffer convert(ByteBuffer from, ILookahead lookahead)
          Convert a byte buffer by decoding using the fromCharset and encoding using the toCharset.
 ByteBuffer convert(CharBuffer from)
          Converts a char buffer to a byte buffer using the toCharset.
 String getFromCharsetName()
          Get charset name of from charset used to decode
 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(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 -
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 -
toCharset -
Method Detail

getFromCharsetName

public String getFromCharsetName()
Get charset name of from charset used to decode

Returns:
- charset name

getToCharsetName

public String getToCharsetName()
Get charset name of to charset used to encode

Returns:
- charset name

clearUnderflow

public byte[] clearUnderflow()
Get and clear the current converted underflow byte array. This results of this method should be wrapped in a ByteBuffer and specified as the from buffer on a call to convert(ByteBuffer) to try convert any remaining bytes.

Returns:
- byte array of underflow or null if the last call to convert(ByteBuffer) did not have underflow.

convert

public ByteBuffer convert(CharBuffer from)
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 -
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.

convert

public ByteBuffer convert(ByteBuffer from,
                          ILookahead lookahead)
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 lenght 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 convert(ByteBuffer). The from buffer specified will be joined with the underflow from a previous call on subsequent calls to convert(ByteBuffer).

Parameters:
from - - byte buffer to convert
lookahead - - lookahead callback
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.

convert

public ByteBuffer convert(ByteBuffer from)
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 convert(ByteBuffer). The from buffer specified will be joined with the underflow from a previous call on subsequent calls to convert(ByteBuffer).

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.


Copyright © 2015 Perforce Software. All Rights Reserved.