@Immutable public final class CharsetHelper extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
CharsetHelper.InputStreamAndCharset |
| Modifier and Type | Method and Description |
|---|---|
static ICommonsOrderedMap<String,Charset> |
getAllCharsets() |
static String |
getAsStringInOtherCharset(String sText,
Charset aCurrentCharset,
Charset aNewCharset) |
static Charset |
getCharsetFromName(String sCharsetName)
Resolve the charset by the specified name.
|
static Charset |
getCharsetFromNameOrNull(String sCharsetName)
Resolve the charset by the specified name.
|
static Charset |
getCharsetFromNameOrNull(String sCharsetName,
Charset aDefault)
Resolve the charset by the specified name.
|
static CharsetHelper.InputStreamAndCharset |
getInputStreamAndCharsetFromBOM(InputStream aIS)
If a BOM is present in the
InputStream it is read and if possible
the charset is automatically determined from the BOM. |
static InputStreamReader |
getReaderByBOM(InputStream aIS,
Charset aFallbackCharset) |
static int |
getUTF8ByteCount(char c) |
static int |
getUTF8ByteCount(char[] aChars)
Get the number of bytes necessary to represent the passed char array as an
UTF-8 string.
|
static int |
getUTF8ByteCount(int c)
Get the number of bytes necessary to represent the passed character.
|
static int |
getUTF8ByteCount(String s)
Get the number of bytes necessary to represent the passed string as an
UTF-8 string.
|
@Nonnull public static Charset getCharsetFromName(@Nonnull @Nonempty String sCharsetName)
Charset.forName(String) is, that this method has no checked
exceptions but only unchecked exceptions.sCharsetName - The charset to be resolved. May neither be null nor
empty.IllegalArgumentException - If the charset could not be resolved.@Nullable public static Charset getCharsetFromNameOrNull(@Nullable String sCharsetName)
Charset.forName(String) is, that this method throws no exceptions.sCharsetName - The charset to be resolved. May be null or empty.null if no such charset was
found.@Nullable public static Charset getCharsetFromNameOrNull(@Nullable String sCharsetName, @Nullable Charset aDefault)
Charset.forName(String) is, that this method throws no exceptions.sCharsetName - The charset to be resolved. May be null or empty.aDefault - the default charset to be returned if none is provided. May be
null.@Nonnull @ReturnsMutableCopy public static ICommonsOrderedMap<String,Charset> getAllCharsets()
@Nullable public static String getAsStringInOtherCharset(@Nullable String sText, @Nonnull Charset aCurrentCharset, @Nonnull Charset aNewCharset)
@Nonnegative public static int getUTF8ByteCount(@Nullable String s)
s - The string to count the length. May be null or empty.@Nonnegative public static int getUTF8ByteCount(@Nullable char[] aChars)
aChars - The characters to count the length. May be null or
empty.@Nonnegative public static int getUTF8ByteCount(char c)
@Nonnegative public static int getUTF8ByteCount(@Nonnegative int c)
c - The character to be evaluated.@Nonnull public static CharsetHelper.InputStreamAndCharset getInputStreamAndCharsetFromBOM(@Nonnull @WillNotClose InputStream aIS)
InputStream it is read and if possible
the charset is automatically determined from the BOM.aIS - The input stream to use. May not be null.null. Always use the input stream contained in
the returned object and never the one passed in as a parameter,
because the returned IS is a push-back InputStream that has a
couple of bytes already buffered!@Nonnull public static InputStreamReader getReaderByBOM(@Nonnull InputStream aIS, @Nonnull Charset aFallbackCharset)
Copyright © 2014–2017 Philip Helger. All rights reserved.