Package com.perforce.p4java
Class CharsetConverter
java.lang.Object
com.perforce.p4java.CharsetConverter
P4Java charset converter class
-
Constructor Summary
ConstructorsConstructorDescriptionCharsetConverter(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
Modifier and TypeMethodDescriptionconvert(ByteBuffer from) Convert a byte buffer by decoding using the fromCharset and encoding using the toCharset.convert(CharBuffer from) Converts a char buffer to a byte buffer using the toCharset.Get charset name of to charset used to encode
-
Constructor Details
-
CharsetConverter
Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.- Parameters:
fromCharset- fromCharsettoCharset- toCharsetignoreBOM- - true to ignore any byte order marks written by the UTF-16 charset and omit them from all return byte buffers
-
CharsetConverter
Creates a new charset converted that decodes/encodes bytes in the specified non-null from/to charset objects specified.- Parameters:
fromCharset- fromCharsettoCharset- toCharset
-
-
Method Details
-
getToCharsetName
Get charset name of to charset used to encode- Returns:
- - charset name
-
convert
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, andByteBuffer.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, andByteBuffer.array()for the byte[] itself. - Throws:
FileEncoderException- on errorFileDecoderException- on error
-