Top Description Inners Fields Constructors Methods
org.glassfish.grizzly.utils

public final Class Charsets

extends Object
Class Inheritance
Imports
java.nio.charset.Charset, .CharsetDecoder, .CharsetEncoder, .UnsupportedCharsetException, java.util.Locale, .Map, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, org.glassfish.grizzly.ThreadCache, .ThreadCache.CachedTypeIndex

Charset utility class.
Author
Alexey Stashok

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static interface
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static volatile boolean
public static final Charset
private static final ConcurrentMap<String, Charset>
private static final ThreadCache.CachedTypeIndex<Charsets.CodecsCache>
public static final int
private static final Charsets.CharsetCodecResolver
public static final String
DEFAULT_CHARACTER_ENCODING

The default character encoding of this Java virtual machine.

public static final Charset
DEFAULT_CHARSET

Returns the default charset of this Java virtual machine.

private static final Charsets.CharsetCodecResolver
public static final Charset

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
drainAllCharsets()

Remove all preloaded charsets.

public static CharsetDecoder

Returns:

the Charset's CharsetDecoder.
getCharsetDecoder
(final Charset charset)

Return the Charset's CharsetDecoder.

public static CharsetEncoder

Returns:

the Charset's CharsetEncoder.
getCharsetEncoder
(final Charset charset)

Return the Charset's CharsetEncoder.

public static Charset

Returns:

Charset
lookupCharset
(final String charsetName)

Lookup a Charset by name.

private static Charsets.CodecsCache
public static void
preloadAllCharsets()

Preloads all Charsets available to the JMV, which makes charset searching faster (at the cost of memory).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

areCharsetsPreloadedback to summary
private static volatile boolean areCharsetsPreloaded
ASCII_CHARSETback to summary
public static final Charset ASCII_CHARSET
charsetAliasMapback to summary
private static final ConcurrentMap<String, Charset> charsetAliasMap
CODECS_CACHEback to summary
private static final ThreadCache.CachedTypeIndex<Charsets.CodecsCache> CODECS_CACHE
CODECS_CACHE_SIZEback to summary
public static final int CODECS_CACHE_SIZE
DECODER_RESOLVERback to summary
private static final Charsets.CharsetCodecResolver DECODER_RESOLVER
DEFAULT_CHARACTER_ENCODINGback to summary
public static final String DEFAULT_CHARACTER_ENCODING

The default character encoding of this Java virtual machine.

DEFAULT_CHARSETback to summary
public static final Charset DEFAULT_CHARSET

Returns the default charset of this Java virtual machine.

See Also
Charset#defaultCharset()
ENCODER_RESOLVERback to summary
private static final Charsets.CharsetCodecResolver ENCODER_RESOLVER
UTF8_CHARSETback to summary
public static final Charset UTF8_CHARSET

Constructor Detail

Charsetsback to summary
public Charsets()

Method Detail

drainAllCharsetsback to summary
public static void drainAllCharsets()

Remove all preloaded charsets.

getCharsetDecoderback to summary
public static CharsetDecoder getCharsetDecoder(final Charset charset)

Return the Charset's CharsetDecoder. The Charsets class maintains the CharsetDecoder thread-local cache. Be aware - this shouldn't be used by multiple threads.

Parameters
charset:Charset

Charset.

Returns:CharsetDecoder

the Charset's CharsetDecoder.

getCharsetEncoderback to summary
public static CharsetEncoder getCharsetEncoder(final Charset charset)

Return the Charset's CharsetEncoder. The Charsets class maintains the CharsetEncoder thread-local cache. Be aware - this shouldn't be used by multiple threads.

Parameters
charset:Charset

Charset.

Returns:CharsetEncoder

the Charset's CharsetEncoder.

lookupCharsetback to summary
public static Charset lookupCharset(final String charsetName)

Lookup a Charset by name. Fixes Charset concurrency issue (http://paul.vox.com/library/post/the-mysteries-of-java-character-set-performance.html)

Returns:Charset

Charset

obtainCodecsCacheback to summary
private static Charsets.CodecsCache obtainCodecsCache()
preloadAllCharsetsback to summary
public static void preloadAllCharsets()

Preloads all Charsets 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 to Charset#forName(java.lang.String).

org.glassfish.grizzly.utils back to summary

private Interface Charsets.CharsetCodecResolver

Known Direct Implementers
org.glassfish.grizzly.utils.Charsets.DecoderResolver, org.glassfish.grizzly.utils.Charsets.EncoderResolver

Method Summary

Modifier and TypeMethod and Description
public Charset
charset(Object element)

public Object

Method Detail

charsetback to summary
public Charset charset(Object element)
newElementback to summary
public Object newElement(Charset charset)
org.glassfish.grizzly.utils back to summary

private final Class Charsets.CodecsCache

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Object[]
private final Object[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public CharsetDecoder
getDecoder(final Charset charset)

public CharsetEncoder
getEncoder(final Charset charset)

private static void
makeFirst(final Object[] array, final int offs, final Object element)

private static Object
obtainElementByCharset(final Object[] array, final Charset charset, final Charsets.CharsetCodecResolver resolver)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decodersback to summary
private final Object[] decoders
encodersback to summary
private final Object[] encoders

Constructor Detail

CodecsCacheback to summary
private CodecsCache()

Method Detail

getDecoderback to summary
public CharsetDecoder getDecoder(final Charset charset)
getEncoderback to summary
public CharsetEncoder getEncoder(final Charset charset)
makeFirstback to summary
private static void makeFirst(final Object[] array, final int offs, final Object element)
obtainElementByCharsetback to summary
private static Object obtainElementByCharset(final Object[] array, final Charset charset, final Charsets.CharsetCodecResolver resolver)
org.glassfish.grizzly.utils back to summary

private final Class Charsets.DecoderResolver

extends Object
implements CharsetCodecResolver
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Charset
public Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DecoderResolverback to summary
private DecoderResolver()

Method Detail

charsetback to summary
public Charset charset(final Object element)

Implements org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver.charset.

Annotations
@Override
newElementback to summary
public Object newElement(final Charset charset)

Implements org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver.newElement.

Annotations
@Override
org.glassfish.grizzly.utils back to summary

private final Class Charsets.EncoderResolver

extends Object
implements CharsetCodecResolver
Class Inheritance
All Implemented Interfaces
org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Charset
public Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EncoderResolverback to summary
private EncoderResolver()

Method Detail

charsetback to summary
public Charset charset(final Object element)

Implements org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver.charset.

Annotations
@Override
newElementback to summary
public Object newElement(final Charset charset)

Implements org.glassfish.grizzly.utils.Charsets.CharsetCodecResolver.newElement.

Annotations
@Override