Class CharsetProvider

java.lang.Object
java.nio.charset.spi.CharsetProvider

public abstract class CharsetProvider extends Object
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 are deployed on the application module path or the application class path. In order to be looked up, charset providers must be visible to the system class loader. See Deploying Service Providers for further detail on deploying a charset provider as a module or on the class path.

For a charset provider deployed in a module, the provides directive must be specified in the module declaration. The provides directive specifies both the service and the service provider. In this case, the service is java.nio.charset.spi.CharsetProvider.

As an example, a charset provider deployed as a module might specify the following directive:

    provides java.nio.charset.spi.CharsetProvider with com.example.ExternalCharsetProvider;

For a charset provider deployed on the class path, it 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.

Since:
1.4
See Also:
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Initializes a new charset provider.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract Charset
    charsetForName(String charsetName)
    Retrieves a charset for the given charset name.
    abstract Iterator<Charset>
    Creates an iterator that iterates over the charsets supported by this provider.

    Methods declared in class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    Modifier and Type
    Method
    Description
    protected Object
    Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.
    boolean
    Compares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    May cause performance issues, deadlocks and hangs.
    final Class<? extends Object>
    Answers the unique instance of java.lang.Class which represents the class of the receiver.
    int
    Answers an integer hash code for the receiver.
    final void
    Causes one thread which is waiting on the receiver to be made ready to run.
    final void
    Causes all threads which are waiting on the receiver to be made ready to run.
    Answers a string containing a concise, human-readable description of the receiver.
    final void
    Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated by notify or notifyAll).
    final void
    wait(long time)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
    final void
    wait(long time, int frac)
    Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated by notify or notifyAll) or the expiration of the timeout.
  • Constructor Details

    • CharsetProvider

      protected CharsetProvider()
      Initializes a new charset provider.
  • Method Details

    • charsets

      public abstract Iterator<Charset> charsets()
      Creates an iterator that iterates over the charsets supported by this provider. This method is used in the implementation of the Charset.availableCharsets method.
      Returns:
      The new iterator
    • charsetForName

      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