CharsetProvider.java revision 89c1feb0a69a7707b271086e749975b3f7acacf7
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package java.nio.charset.spi;
18
19import java.nio.charset.Charset;
20import java.util.Iterator;
21
22/**
23 * The service provider class for character sets.
24 *
25 * @since Android 1.0
26 */
27public abstract class CharsetProvider {
28
29    // The permission required to construct a new provider.
30    private static final RuntimePermission CONSTRUCT_PERM = new RuntimePermission(
31            "charsetProvider"); //$NON-NLS-1$
32
33    /**
34     * Constructor for subclassing with concrete types.
35     *
36     * @throws SecurityException
37     *             if there is a security manager installed that does not permit
38     *             the runtime permission labeled "charsetProvider".
39     * @since Android 1.0
40     */
41    protected CharsetProvider() {
42        SecurityManager securityManager = System.getSecurityManager();
43        if (securityManager != null)
44            securityManager.checkPermission(CONSTRUCT_PERM);
45    }
46
47    /**
48     * Returns an iterator over all the available charsets.
49     *
50     * @return the iterator.
51     * @since Android 1.0
52     */
53    public abstract Iterator<Charset> charsets();
54
55    /**
56     * Returns the named charset.
57     * <p>
58     * If the charset is unavailable the method returns <code>null</code>.
59     * </p>
60     *
61     * @param charsetName
62     *            the canonical or alias name of a character set.
63     * @return the charset, or <code>null</code> if unavailable.
64     * @since Android 1.0
65     */
66    public abstract Charset charsetForName(String charsetName);
67}
68