Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/java/nio/charset/spi/CharsetProvider.java
38918 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.nio.charset.spi;2627import java.nio.charset.Charset;28import java.util.Iterator;293031/**32* Charset service-provider class.33*34* <p> A charset provider is a concrete subclass of this class that has a35* zero-argument constructor and some number of associated charset36* implementation classes. Charset providers may be installed in an instance37* of the Java platform as extensions, that is, jar files placed into any of38* the usual extension directories. Providers may also be made available by39* adding them to the applet or application class path or by some other40* platform-specific means. Charset providers are looked up via the current41* thread's {@link java.lang.Thread#getContextClassLoader() context class42* loader}.43*44* <p> A charset provider identifies itself with a provider-configuration file45* named <tt>java.nio.charset.spi.CharsetProvider</tt> in the resource46* directory <tt>META-INF/services</tt>. The file should contain a list of47* fully-qualified concrete charset-provider class names, one per line. A line48* is terminated by any one of a line feed (<tt>'\n'</tt>), a carriage return49* (<tt>'\r'</tt>), or a carriage return followed immediately by a line feed.50* Space and tab characters surrounding each name, as well as blank lines, are51* ignored. The comment character is <tt>'#'</tt> (<tt>'\u0023'</tt>); on52* each line all characters following the first comment character are ignored.53* The file must be encoded in UTF-8.54*55* <p> If a particular concrete charset provider class is named in more than56* one configuration file, or is named in the same configuration file more than57* once, then the duplicates will be ignored. The configuration file naming a58* particular provider need not be in the same jar file or other distribution59* unit as the provider itself. The provider must be accessible from the same60* class loader that was initially queried to locate the configuration file;61* this is not necessarily the class loader that loaded the file. </p>62*63*64* @author Mark Reinhold65* @author JSR-51 Expert Group66* @since 1.467*68* @see java.nio.charset.Charset69*/7071public abstract class CharsetProvider {7273/**74* Initializes a new charset provider.75*76* @throws SecurityException77* If a security manager has been installed and it denies78* {@link RuntimePermission}<tt>("charsetProvider")</tt>79*/80protected CharsetProvider() {81SecurityManager sm = System.getSecurityManager();82if (sm != null)83sm.checkPermission(new RuntimePermission("charsetProvider"));84}8586/**87* Creates an iterator that iterates over the charsets supported by this88* provider. This method is used in the implementation of the {@link89* java.nio.charset.Charset#availableCharsets Charset.availableCharsets}90* method.91*92* @return The new iterator93*/94public abstract Iterator<Charset> charsets();9596/**97* Retrieves a charset for the given charset name.98*99* @param charsetName100* The name of the requested charset; may be either101* a canonical name or an alias102*103* @return A charset object for the named charset,104* or <tt>null</tt> if the named charset105* is not supported by this provider106*/107public abstract Charset charsetForName(String charsetName);108109}110111112