public class DataConverter extends Object
DataConverter
object is used to convert binary data
to text data and vice versa. According to RFC 6455 a particular text
frame might include a partial UTF-8 sequence; however, the whole
message MUST contain valid UTF-8.DataFrame
Constructor and Description |
---|
DataConverter()
Constructor for the
DataConverter object. |
DataConverter(String charset)
Constructor for the
DataConverter object. |
Modifier and Type | Method and Description |
---|---|
String |
convert(byte[] binary)
This method is used to convert data using the character encoding
specified when constructing the converter.
|
String |
convert(byte[] binary,
int offset,
int size)
This method is used to convert data using the character encoding
specified when constructing the converter.
|
byte[] |
convert(String text)
This method is used to convert text using the character encoding
specified when constructing the converter.
|
public DataConverter()
DataConverter
object. By default
this uses UTF-8 character encoding to convert text data as this
is what is required for RFC 6455 section 5.6.public DataConverter(String charset)
DataConverter
object. This can be
used to specific a character encoding other than UTF-8. However it
is not recommended as RFC 6455 section 5.6 suggests the frame must
contain valid UTF-8 data.charset
- the character encoding to be usedpublic byte[] convert(String text)
text
- this is the string to convert to a byte arraypublic String convert(byte[] binary)
text
- this is the byte array to convert to a stringpublic String convert(byte[] binary, int offset, int size)
text
- this is the byte array to convert to a stringoffset
- the is the offset to read the bytes fromsize
- this is the number of bytes to be usedCopyright © 2024. All rights reserved.