jdk/src/java.base/share/classes/java/nio/charset/spi/CharsetProvider.java
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 25859 3317bb8137f4
child 32143 394ab6a6658d
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 22053
diff changeset
     2
 * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.nio.charset.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.charset.Charset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Charset service-provider class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p> A charset provider is a concrete subclass of this class that has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * zero-argument constructor and some number of associated charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * implementation classes.  Charset providers may be installed in an instance
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    38
 * of the Java platform as extensions.  Providers may also be made available by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * adding them to the applet or application class path or by some other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * platform-specific means.  Charset providers are looked up via the current
18574
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    41
 * thread's {@link java.lang.Thread#getContextClassLoader() context class
4aeaeb541678 8019380: doclint warnings in java.nio, java.nio.file.**, java.nio.channels.**
alanb
parents: 18164
diff changeset
    42
 * loader}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p> A charset provider identifies itself with a provider-configuration file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * named <tt>java.nio.charset.spi.CharsetProvider</tt> in the resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * directory <tt>META-INF/services</tt>.  The file should contain a list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * fully-qualified concrete charset-provider class names, one per line.  A line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * is terminated by any one of a line feed (<tt>'\n'</tt>), a carriage return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * (<tt>'\r'</tt>), or a carriage return followed immediately by a line feed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Space and tab characters surrounding each name, as well as blank lines, are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * ignored.  The comment character is <tt>'#'</tt> (<tt>'&#92;u0023'</tt>); on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * each line all characters following the first comment character are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * The file must be encoded in UTF-8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p> If a particular concrete charset provider class is named in more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * one configuration file, or is named in the same configuration file more than
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * once, then the duplicates will be ignored.  The configuration file naming a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * particular provider need not be in the same jar file or other distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * unit as the provider itself.  The provider must be accessible from the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * class loader that was initially queried to locate the configuration file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * this is not necessarily the class loader that loaded the file. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see java.nio.charset.Charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public abstract class CharsetProvider {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
22053
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    73
    private static Void checkPermission() {
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    74
        SecurityManager sm = System.getSecurityManager();
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    75
        if (sm != null)
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    76
            sm.checkPermission(new RuntimePermission("charsetProvider"));
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    77
        return null;
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    78
    }
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    79
    private CharsetProvider(Void ignore) { }
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    80
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
    82
     * Initializes a new charset provider.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws  SecurityException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *          If a security manager has been installed and it denies
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *          {@link RuntimePermission}<tt>("charsetProvider")</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    protected CharsetProvider() {
22053
09b848a5794d 6706208: (cs) CharsetProvider permission check cleanup
alanb
parents: 18574
diff changeset
    89
        this(checkPermission());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Creates an iterator that iterates over the charsets supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * provider.  This method is used in the implementation of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * java.nio.charset.Charset#availableCharsets Charset.availableCharsets}
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
    96
     * method.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return  The new iterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public abstract Iterator<Charset> charsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
18164
68f1bc4eadd4 8016370: javadoc warnings, unexpected </p> mostly
alanb
parents: 5506
diff changeset
   103
     * Retrieves a charset for the given charset name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param  charsetName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *         The name of the requested charset; may be either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *         a canonical name or an alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @return  A charset object for the named charset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *          or <tt>null</tt> if the named charset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *          is not supported by this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public abstract Charset charsetForName(String charsetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
}