CharsetProvider
Stay organized with collections
Save and categorize content based on your preferences.
Charset service-provider class.
A charset provider is a concrete subclass of this class that has a
zero-argument constructor and some number of associated charset
implementation classes. Charset providers may be installed in an instance
of the Java platform as extensions, that is, jar files placed into any of
the usual extension directories. Providers may also be made available by
adding them to the applet or application class path or by some other
platform-specific means. Charset providers are looked up via the current
thread's context class
loader
.
A charset provider identifies itself with a provider-configuration file
named java.nio.charset.spi.CharsetProvider in the resource
directory META-INF/services. The file should contain a list of
fully-qualified concrete charset-provider class names, one per line. A line
is terminated by any one of a line feed ('\n'), a carriage return
('\r'), or a carriage return followed immediately by a line feed.
Space and tab characters surrounding each name, as well as blank lines, are
ignored. The comment character is '#' ('\u0023'); on
each line all characters following the first comment character are ignored.
The file must be encoded in UTF-8.
If a particular concrete charset provider class is named in more than
one configuration file, or is named in the same configuration file more than
once, then the duplicates will be ignored. The configuration file naming a
particular provider need not be in the same jar file or other distribution
unit as the provider itself. The provider must be accessible from the same
class loader that was initially queried to locate the configuration file;
this is not necessarily the class loader that loaded the file.
Protected Constructor Summary
Inherited Method Summary
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this Object .
|
boolean
|
equals( Object obj)
Compares this instance with the specified object and indicates if they
are equal.
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
int
|
hashCode()
Returns an integer hash code for this object.
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
final
void
|
wait(long timeout, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait(long timeout)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
Protected Constructors
protected
CharsetProvider
()
Initializes a new charset provider.
Public Methods
public
abstract
Charset
charsetForName
(String charsetName)
Retrieves a charset for the given charset name.
Parameters
charsetName |
The name of the requested charset; may be either
a canonical name or an alias |
Returns
- A charset object for the named charset,
or null if the named charset
is not supported by this provider
Creates an iterator that iterates over the charsets supported by this
provider. This method is used in the implementation of the Charset.availableCharsets
method.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eCharsetProvider\u003c/code\u003e is an abstract class that serves as a service provider for character sets (charsets) in Java.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can create custom charset providers by extending this class and implementing the required methods.\u003c/p\u003e\n"],["\u003cp\u003eCharset providers are discovered and loaded using the Java Service Provider Interface (SPI) through configuration files.\u003c/p\u003e\n"],["\u003cp\u003eThese configuration files list the fully qualified names of concrete \u003ccode\u003eCharsetProvider\u003c/code\u003e implementations and are located in the \u003ccode\u003eMETA-INF/services\u003c/code\u003e directory.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCharsetProvider\u003c/code\u003e implementations allow for retrieving specific charsets by name (\u003ccode\u003echarsetForName\u003c/code\u003e) and iterating over the supported charsets (\u003ccode\u003echarsets\u003c/code\u003e).\u003c/p\u003e\n"]]],["Charset providers, concrete subclasses, are installed as extensions or via class paths. They are identified through a configuration file ( `java.nio.charset.spi.CharsetProvider` in `META-INF/services`) listing fully-qualified class names, UTF-8 encoded, with duplicates ignored. Providers initialize with a zero-argument constructor, retrieve a charset via `charsetForName(String)`, and offer supported charsets through an iterator with `charsets()`. They rely on the context class loader for lookup.\n"],null,["# CharsetProvider\n\npublic abstract class **CharsetProvider** extends [Object](../../../../../reference/java/lang/Object.html) \nCharset service-provider class.\n\nA charset provider is a concrete subclass of this class that has a\nzero-argument constructor and some number of associated charset\nimplementation classes. Charset providers may be installed in an instance\nof the Java platform as extensions, that is, jar files placed into any of\nthe usual extension directories. Providers may also be made available by\nadding them to the applet or application class path or by some other\nplatform-specific means. Charset providers are looked up via the current\nthread's [context class\nloader](../../../../../reference/java/lang/Thread.html#getContextClassLoader()).\n\nA charset provider identifies itself with a provider-configuration file\nnamed java.nio.charset.spi.CharsetProvider in the resource\ndirectory META-INF/services. The file should contain a list of\nfully-qualified concrete charset-provider class names, one per line. A line\nis terminated by any one of a line feed ('\\\\n'), a carriage return\n('\\\\r'), or a carriage return followed immediately by a line feed.\nSpace and tab characters surrounding each name, as well as blank lines, are\nignored. The comment character is '#' ('\\\\u0023'); on\neach line all characters following the first comment character are ignored.\nThe file must be encoded in UTF-8.\n\nIf a particular concrete charset provider class is named in more than\none configuration file, or is named in the same configuration file more than\nonce, then the duplicates will be ignored. The configuration file naming a\nparticular provider need not be in the same jar file or other distribution\nunit as the provider itself. The provider must be accessible from the same\nclass loader that was initially queried to locate the configuration file;\nthis is not necessarily the class loader that loaded the file.\n\n\u003cbr /\u003e\n\n##### See Also\n\n- [Charset](../../../../../reference/java/nio/charset/Charset.html) \n\n### Protected Constructor Summary\n\n|---|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| | [CharsetProvider](../../../../../reference/java/nio/charset/spi/CharsetProvider.html#CharsetProvider())() Initializes a new charset provider. |\n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Charset](../../../../../reference/java/nio/charset/Charset.html) | [charsetForName](../../../../../reference/java/nio/charset/spi/CharsetProvider.html#charsetForName(java.lang.String))([String](../../../../../reference/java/lang/String.html) charsetName) Retrieves a charset for the given charset name. |\n| abstract [Iterator](../../../../../reference/java/util/Iterator.html)\\\u003c[Charset](../../../../../reference/java/nio/charset/Charset.html)\\\u003e | [charsets](../../../../../reference/java/nio/charset/spi/CharsetProvider.html#charsets())() Creates an iterator that iterates over the charsets supported by this provider. |\n\n### Inherited Method Summary\n\nFrom class [java.lang.Object](../../../../../reference/java/lang/Object.html) \n\n|-------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Object](../../../../../reference/java/lang/Object.html) | [clone](../../../../../reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |\n| boolean | [equals](../../../../../reference/java/lang/Object.html#equals(java.lang.Object))([Object](../../../../../reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |\n| void | [finalize](../../../../../reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |\n| final [Class](../../../../../reference/java/lang/Class.html)\\\u003c?\\\u003e | [getClass](../../../../../reference/java/lang/Object.html#getClass())() Returns the unique instance of [Class](../../../../../reference/java/lang/Class.html) that represents this object's class. |\n| int | [hashCode](../../../../../reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |\n| final void | [notify](../../../../../reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| final void | [notifyAll](../../../../../reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |\n| [String](../../../../../reference/java/lang/String.html) | [toString](../../../../../reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |\n| final void | [wait](../../../../../reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../../../reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |\n| final void | [wait](../../../../../reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |\n\nProtected Constructors\n----------------------\n\n#### protected\n**CharsetProvider**\n()\n\nInitializes a new charset provider. \n\n##### Throws\n\n| [SecurityException](../../../../../reference/java/lang/SecurityException.html) | If a security manager has been installed and it denies [RuntimePermission](../../../../../reference/java/lang/RuntimePermission.html)(\"charsetProvider\") |\n|--------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n\nPublic Methods\n--------------\n\n#### public abstract [Charset](../../../../../reference/java/nio/charset/Charset.html)\n**charsetForName**\n([String](../../../../../reference/java/lang/String.html) charsetName)\n\nRetrieves a charset for the given charset name. \n\n##### Parameters\n\n| charsetName | The name of the requested charset; may be either a canonical name or an alias |\n|-------------|-------------------------------------------------------------------------------|\n\n##### Returns\n\n- A charset object for the named charset, or null if the named charset is not supported by this provider \n\n#### public abstract [Iterator](../../../../../reference/java/util/Iterator.html)\\\u003c[Charset](../../../../../reference/java/nio/charset/Charset.html)\\\u003e\n**charsets**\n()\n\nCreates an iterator that iterates over the charsets supported by this\nprovider. This method is used in the implementation of the [Charset.availableCharsets](../../../../../reference/java/nio/charset/Charset.html#availableCharsets())\nmethod. \n\n##### Returns\n\n- The new iterator"]]