Package com.perforce.p4java
Class CharsetConverter
- java.lang.Object
-
- com.perforce.p4java.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
-
-
-
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
- fromCharsettoCharset
- toCharsetignoreBOM
- - 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
- fromCharsettoCharset
- 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, andByteBuffer.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, andByteBuffer.array()
for the byte[] itself. - Throws:
FileEncoderException
- on errorFileDecoderException
- on error
-
-