Package org.simpleframework.http.socket
Class DataConverter
- java.lang.Object
-
- org.simpleframework.http.socket.DataConverter
-
public class DataConverter extends java.lang.Object
TheDataConverter
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.- Author:
- Niall Gallagher
- See Also:
DataFrame
-
-
Constructor Summary
Constructors Constructor Description DataConverter()
Constructor for theDataConverter
object.DataConverter(java.lang.String charset)
Constructor for theDataConverter
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
convert(byte[] binary)
This method is used to convert data using the character encoding specified when constructing the converter.java.lang.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(java.lang.String text)
This method is used to convert text using the character encoding specified when constructing the converter.
-
-
-
Constructor Detail
-
DataConverter
public DataConverter()
Constructor for theDataConverter
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.
-
DataConverter
public DataConverter(java.lang.String charset)
Constructor for theDataConverter
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.- Parameters:
charset
- the character encoding to be used
-
-
Method Detail
-
convert
public byte[] convert(java.lang.String text)
This method is used to convert text using the character encoding specified when constructing the converter. Typically this will use UTF-8 as required by RFC 6455.- Parameters:
text
- this is the string to convert to a byte array- Returns:
- a byte array decoded using the specified encoding
-
convert
public java.lang.String convert(byte[] binary)
This method is used to convert data using the character encoding specified when constructing the converter. Typically this will use UTF-8 as required by RFC 6455.- Parameters:
text
- this is the byte array to convert to a string- Returns:
- a string encoded using the specified encoding
-
convert
public java.lang.String convert(byte[] binary, int offset, int size)
This method is used to convert data using the character encoding specified when constructing the converter. Typically this will use UTF-8 as required by RFC 6455.- Parameters:
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 used- Returns:
- a string encoded using the specified encoding
-
-