Package org.glassfish.grizzly.utils
Class Charsets
- java.lang.Object
-
- org.glassfish.grizzly.utils.Charsets
-
public final class Charsets extends Object
Charset utility class.- Author:
- Alexey Stashok
-
-
Field Summary
Fields Modifier and Type Field Description static Charset
ASCII_CHARSET
static int
CODECS_CACHE_SIZE
static String
DEFAULT_CHARACTER_ENCODING
The default character encoding of this Java virtual machine.static Charset
DEFAULT_CHARSET
Returns the default charset of this Java virtual machine.static Charset
UTF8_CHARSET
-
Constructor Summary
Constructors Constructor Description Charsets()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
drainAllCharsets()
Remove all preloaded charsets.static CharsetDecoder
getCharsetDecoder(Charset charset)
Return theCharset
'sCharsetDecoder
.static CharsetEncoder
getCharsetEncoder(Charset charset)
Return theCharset
'sCharsetEncoder
.static Charset
lookupCharset(String charsetName)
Lookup aCharset
by name.static void
preloadAllCharsets()
Preloads allCharset
s available to the JMV, which makes charset searching faster (at the cost of memory).
-
-
-
Field Detail
-
DEFAULT_CHARACTER_ENCODING
public static final String DEFAULT_CHARACTER_ENCODING
The default character encoding of this Java virtual machine.
-
ASCII_CHARSET
public static final Charset ASCII_CHARSET
-
UTF8_CHARSET
public static final Charset UTF8_CHARSET
-
DEFAULT_CHARSET
public static final Charset DEFAULT_CHARSET
Returns the default charset of this Java virtual machine.- See Also:
Charset.defaultCharset()
-
CODECS_CACHE_SIZE
public static final int CODECS_CACHE_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
lookupCharset
public static Charset lookupCharset(String charsetName)
Lookup aCharset
by name. Fixes Charset concurrency issue (http://paul.vox.com/library/post/the-mysteries-of-java-character-set-performance.html)- Parameters:
charsetName
-- Returns:
Charset
-
preloadAllCharsets
public static void preloadAllCharsets()
Preloads allCharset
s available to the JMV, which makes charset searching faster (at the cost of memory). The speed gain is most noticable in the case of non-existing charsets as it allows us to avoid an expensive call toCharset.forName(java.lang.String)
.
-
drainAllCharsets
public static void drainAllCharsets()
Remove all preloaded charsets.
-
getCharsetDecoder
public static CharsetDecoder getCharsetDecoder(Charset charset)
Return theCharset
'sCharsetDecoder
. The Charsets class maintains theCharsetDecoder
thread-local cache. Be aware - this shouldn't be used by multiple threads.- Parameters:
charset
-Charset
.- Returns:
- the
Charset
'sCharsetDecoder
.
-
getCharsetEncoder
public static CharsetEncoder getCharsetEncoder(Charset charset)
Return theCharset
'sCharsetEncoder
. The Charsets class maintains theCharsetEncoder
thread-local cache. Be aware - this shouldn't be used by multiple threads.- Parameters:
charset
-Charset
.- Returns:
- the
Charset
'sCharsetEncoder
.
-
-