Package com.illumon.util
Class EncodingUtil
java.lang.Object
com.illumon.util.EncodingUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.commons.io.ByteOrderMark[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.commons.io.ByteOrderMark[]
getBOMsForEncoding
(com.fishlib.base.string.EncodingInfo encoding) Get an array containing the possiblebyte order marks
that could be present within a file of the specified encoding.static com.fishlib.base.string.EncodingInfo
getEncodingInfoForCharset
(String charsetName) Get theEncodingInfo
associated with a particular charset namestatic com.fishlib.base.string.EncodingInfo
getEncodingInfoForCharset
(Charset charSet) Get theEncodingInfo
associated with a particularCharset
static String
getUtf8String
(ByteBuffer source) Extract a UTF-8 encoded string from the given buffer.static void
putUtf8String
(ByteBuffer destination, String value) Encode the given string in UTF-8 format into the given ByteBuffer.
-
Field Details
-
EMPTY_BOM_ARRAY
public static final org.apache.commons.io.ByteOrderMark[] EMPTY_BOM_ARRAY
-
-
Constructor Details
-
EncodingUtil
public EncodingUtil()
-
-
Method Details
-
getEncodingInfoForCharset
@NotNull public static com.fishlib.base.string.EncodingInfo getEncodingInfoForCharset(@NotNull Charset charSet) throws IllegalArgumentException Get theEncodingInfo
associated with a particularCharset
- Parameters:
charSet
- The charset- Returns:
- the matching
EncodingInfo
- Throws:
IllegalArgumentException
- if there is no associated encoding
-
getEncodingInfoForCharset
public static com.fishlib.base.string.EncodingInfo getEncodingInfoForCharset(@NotNull String charsetName) Get theEncodingInfo
associated with a particular charset name- Parameters:
charsetName
- the charset- Returns:
- the matching
EncodingInfo
- Throws:
IllegalArgumentException
- if there is no associated encoding
-
getBOMsForEncoding
@NotNull public static org.apache.commons.io.ByteOrderMark[] getBOMsForEncoding(com.fishlib.base.string.EncodingInfo encoding) Get an array containing the possiblebyte order marks
that could be present within a file of the specified encoding. This is intended for use withBOMInputStream
- Parameters:
encoding
- The encoding.- Returns:
- An array containing the possible
BOMs
for the encoding.
-
putUtf8String
Encode the given string in UTF-8 format into the given ByteBuffer. The string is encoded as an int length followed by the encoded bytes.- Parameters:
destination
- a ByteBuffer in which to encode the string. The buffer must be big enough for the encoded string.value
- the String value to encode.- Throws:
BufferOverflowException
- if the destination isn't big enough.
-
getUtf8String
Extract a UTF-8 encoded string from the given buffer. The buffer must be positioned at the start of the encoding, which is an int length followed by the UTF-8 encoded bytes. The buffer is advanced to the end of the string.- Parameters:
source
- a ByteBuffer positioned at the string encoded as length + UTF-8 encoded bytes.- Returns:
- a new String extracted from the buffer
- Throws:
BufferUnderflowException
- if there isn't enough data in the source ByteBufferIllegalArgumentException
- if there is a decoding error
-