Package de.xima.fc.utils
Class ByteOrderMarkUtil
java.lang.Object
de.xima.fc.utils.ByteOrderMarkUtil
Utility class for working with byte order marks.
- Since:
- 7.0.0
- Author:
- XIMA MEDIA GmbH
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
getByteOrderMarkBytes
(Charset charset) static EByteOrderMarkSupport
getByteOrderMarkSupport
(Charset charset) static boolean
isByteOrderMarkSupported
(Charset charset) static byte[]
toBytes
(String data, Charset charset, EByteOrderMarkMode mode) Converts the given string to its byte representations according to the given charset.
-
Constructor Details
-
ByteOrderMarkUtil
public ByteOrderMarkUtil()
-
-
Method Details
-
getByteOrderMarkBytes
- Parameters:
charset
- Charset to check.- Returns:
- The bytes representing the byte order mark in that charset. Empty byte array when the charset does not support a byte order mark.
-
getByteOrderMarkSupport
- Parameters:
charset
- Charset to check.- Returns:
- The byte order mark support for the given charset.
-
isByteOrderMarkSupported
- Parameters:
charset
- Charset to check.- Returns:
true
if the given charset supports byte order marks.
-
toBytes
@Nonnull public static byte[] toBytes(@Nullable String data, @Nonnull Charset charset, EByteOrderMarkMode mode) Converts the given string to its byte representations according to the given charset. Optionally adds a BOM (byte-order mark) when supported by the charset. Only UTF-1, UTF-7, UTF_8, UTF-16 and UTF-32 charsets support this byte mark. In particularStandardCharsets.UTF_16BE
andStandardCharsets.UTF_16LE
require no BOM mark to be present. No byte order mark is added when the given data isnull
orempty
.- Parameters:
data
- String to encode. When the first character is a BOM, it is removed.charset
- Charset to use.mode
- WhenADD
, always adds the BOM (if missing) when the charset is a unicode charset. IfREMOVE
, removes the BOM so that it is not present in the returned byte array. WhenAUTO
(ornull
), only adds the BOM when required by the charset.- Returns:
- The bytes representing the data according to the given charset, optionally with a byte-order mark
according to the given
useBom
. Empty byte array when the given data isnull
orempty
. - Throws:
NullPointerException
- When the given charset isnull
.
-