java.nio.charset.spi.CharsetProvider Java Examples

The following examples show how to use java.nio.charset.spi.CharsetProvider. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Bytecoder   Author: mirkosertic   File: Charset.java    License: Apache License 2.0 6 votes vote down vote up
private static CharsetProvider[] extendedProviders() {
    return AccessController.doPrivileged(new PrivilegedAction<>() {
            public CharsetProvider[] run() {
                CharsetProvider[] cps = new CharsetProvider[1];
                int n = 0;
                ServiceLoader<CharsetProvider> sl =
                    ServiceLoader.loadInstalled(CharsetProvider.class);
                for (CharsetProvider cp : sl) {
                    if (n + 1 > cps.length) {
                        cps = Arrays.copyOf(cps, cps.length << 1);
                    }
                    cps[n++] = cp;
                }
                return n == cps.length ? cps : Arrays.copyOf(cps, n);
            }});
}
 
Example #2
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Charset.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static CharsetProvider[] extendedProviders() {
    return AccessController.doPrivileged(new PrivilegedAction<>() {
            public CharsetProvider[] run() {
                CharsetProvider[] cps = new CharsetProvider[1];
                int n = 0;
                ServiceLoader<CharsetProvider> sl =
                    ServiceLoader.loadInstalled(CharsetProvider.class);
                for (CharsetProvider cp : sl) {
                    if (n + 1 > cps.length) {
                        cps = Arrays.copyOf(cps, cps.length << 1);
                    }
                    cps[n++] = cp;
                }
                return n == cps.length ? cps : Arrays.copyOf(cps, n);
            }});
}
 
Example #3
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Charset.java    License: Apache License 2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #4
Source Project: dragonwell8_jdk   Author: alibaba   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #5
Source Project: TencentKona-8   Author: Tencent   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #7
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: Charset.java    License: MIT License 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #9
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #10
Source Project: Bytecoder   Author: mirkosertic   File: Charset.java    License: Apache License 2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #11
Source Project: Bytecoder   Author: mirkosertic   File: Charset.java    License: Apache License 2.0 5 votes vote down vote up
private static Charset lookupExtendedCharset(String charsetName) {
    if (!VM.isBooted())  // see lookupViaProviders()
        return null;
    CharsetProvider[] ecps = ExtendedProviderHolder.extendedProviders;
    for (CharsetProvider cp : ecps) {
        Charset cs = cp.charsetForName(charsetName);
        if (cs != null)
            return cs;
    }
    return null;
}
 
Example #12
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #13
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupExtendedCharset(String charsetName) {
    if (!VM.isBooted())  // see lookupViaProviders()
        return null;
    CharsetProvider[] ecps = ExtendedProviderHolder.extendedProviders;
    for (CharsetProvider cp : ecps) {
        Charset cs = cp.charsetForName(charsetName);
        if (cs != null)
            return cs;
    }
    return null;
}
 
Example #14
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #15
Source Project: Java8CN   Author: Java8-CNAPI-Team   File: Charset.java    License: Apache License 2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #16
Source Project: hottub   Author: dsrg-uoft   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #17
Source Project: openjdk-8-source   Author: keerath   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #18
Source Project: openjdk-8   Author: bpupadhyaya   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #19
Source Project: jdk8u_jdk   Author: JetBrains   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #20
Source Project: jdk8u-jdk   Author: frohoff   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #21
Source Project: jdk-1.7-annotated   Author: ZhaoX   File: Charset.java    License: Apache License 2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator i = providers(); i.hasNext();) {
                            CharsetProvider cp = (CharsetProvider)i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #22
Source Project: jdk8u-dev-jdk   Author: frohoff   File: Charset.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static Charset lookupViaProviders(final String charsetName) {

        // The runtime startup sequence looks up standard charsets as a
        // consequence of the VM's invocation of System.initializeSystemClass
        // in order to, e.g., set system properties and encode filenames.  At
        // that point the application class loader has not been initialized,
        // however, so we can't look for providers because doing so will cause
        // that loader to be prematurely initialized with incomplete
        // information.
        //
        if (!sun.misc.VM.isBooted())
            return null;

        if (gate.get() != null)
            // Avoid recursive provider lookups
            return null;
        try {
            gate.set(gate);

            return AccessController.doPrivileged(
                new PrivilegedAction<Charset>() {
                    public Charset run() {
                        for (Iterator<CharsetProvider> i = providers();
                             i.hasNext();) {
                            CharsetProvider cp = i.next();
                            Charset cs = cp.charsetForName(charsetName);
                            if (cs != null)
                                return cs;
                        }
                        return null;
                    }
                });

        } finally {
            gate.set(null);
        }
    }
 
Example #23
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Charset.java    License: Apache License 2.0 4 votes vote down vote up
private static Iterator<CharsetProvider> providers() {
    return new Iterator<CharsetProvider>() {

            ClassLoader cl = ClassLoader.getSystemClassLoader();
            ServiceLoader<CharsetProvider> sl =
                ServiceLoader.load(CharsetProvider.class, cl);
            Iterator<CharsetProvider> i = sl.iterator();

            CharsetProvider next = null;

            private boolean getNext() {
                while (next == null) {
                    try {
                        if (!i.hasNext())
                            return false;
                        next = i.next();
                    } catch (ServiceConfigurationError sce) {
                        if (sce.getCause() instanceof SecurityException) {
                            // Ignore security exceptions
                            continue;
                        }
                        throw sce;
                    }
                }
                return true;
            }

            public boolean hasNext() {
                return getNext();
            }

            public CharsetProvider next() {
                if (!getNext())
                    throw new NoSuchElementException();
                CharsetProvider n = next;
                next = null;
                return n;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
}
 
Example #24
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Charset.java    License: Apache License 2.0 4 votes vote down vote up
private static Charset lookupExtendedCharset(String charsetName) {
    CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
    return (ecp != null) ? ecp.charsetForName(charsetName) : null;
}
 
Example #25
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Charset.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a sorted map from canonical charset names to charset objects.
 *
 * <p> The map returned by this method will have one entry for each charset
 * for which support is available in the current Java virtual machine.  If
 * two or more supported charsets have the same canonical name then the
 * resulting map will contain just one of them; which one it will contain
 * is not specified. </p>
 *
 * <p> The invocation of this method, and the subsequent use of the
 * resulting map, may cause time-consuming disk or network I/O operations
 * to occur.  This method is provided for applications that need to
 * enumerate all of the available charsets, for example to allow user
 * charset selection.  This method is not used by the {@link #forName
 * forName} method, which instead employs an efficient incremental lookup
 * algorithm.
 *
 * <p> This method may return different results at different times if new
 * charset providers are dynamically made available to the current Java
 * virtual machine.  In the absence of such changes, the charsets returned
 * by this method are exactly those that can be retrieved via the {@link
 * #forName forName} method.  </p>
 *
 * @return An immutable, case-insensitive map from canonical charset names
 *         to charset objects
 */
public static SortedMap<String,Charset> availableCharsets() {
    return AccessController.doPrivileged(
        new PrivilegedAction<SortedMap<String,Charset>>() {
            public SortedMap<String,Charset> run() {
                TreeMap<String,Charset> m =
                    new TreeMap<String,Charset>(
                        ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
                put(standardProvider.charsets(), m);
                CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
                if (ecp != null)
                    put(ecp.charsets(), m);
                for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
                    CharsetProvider cp = i.next();
                    put(cp.charsets(), m);
                }
                return Collections.unmodifiableSortedMap(m);
            }
        });
}
 
Example #26
Source Project: dragonwell8_jdk   Author: alibaba   File: Charset.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Iterator<CharsetProvider> providers() {
    return new Iterator<CharsetProvider>() {

            ClassLoader cl = ClassLoader.getSystemClassLoader();
            ServiceLoader<CharsetProvider> sl =
                ServiceLoader.load(CharsetProvider.class, cl);
            Iterator<CharsetProvider> i = sl.iterator();

            CharsetProvider next = null;

            private boolean getNext() {
                while (next == null) {
                    try {
                        if (!i.hasNext())
                            return false;
                        next = i.next();
                    } catch (ServiceConfigurationError sce) {
                        if (sce.getCause() instanceof SecurityException) {
                            // Ignore security exceptions
                            continue;
                        }
                        throw sce;
                    }
                }
                return true;
            }

            public boolean hasNext() {
                return getNext();
            }

            public CharsetProvider next() {
                if (!getNext())
                    throw new NoSuchElementException();
                CharsetProvider n = next;
                next = null;
                return n;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
}
 
Example #27
Source Project: dragonwell8_jdk   Author: alibaba   File: Charset.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Charset lookupExtendedCharset(String charsetName) {
    CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
    return (ecp != null) ? ecp.charsetForName(charsetName) : null;
}
 
Example #28
Source Project: dragonwell8_jdk   Author: alibaba   File: Charset.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructs a sorted map from canonical charset names to charset objects.
 *
 * <p> The map returned by this method will have one entry for each charset
 * for which support is available in the current Java virtual machine.  If
 * two or more supported charsets have the same canonical name then the
 * resulting map will contain just one of them; which one it will contain
 * is not specified. </p>
 *
 * <p> The invocation of this method, and the subsequent use of the
 * resulting map, may cause time-consuming disk or network I/O operations
 * to occur.  This method is provided for applications that need to
 * enumerate all of the available charsets, for example to allow user
 * charset selection.  This method is not used by the {@link #forName
 * forName} method, which instead employs an efficient incremental lookup
 * algorithm.
 *
 * <p> This method may return different results at different times if new
 * charset providers are dynamically made available to the current Java
 * virtual machine.  In the absence of such changes, the charsets returned
 * by this method are exactly those that can be retrieved via the {@link
 * #forName forName} method.  </p>
 *
 * @return An immutable, case-insensitive map from canonical charset names
 *         to charset objects
 */
public static SortedMap<String,Charset> availableCharsets() {
    return AccessController.doPrivileged(
        new PrivilegedAction<SortedMap<String,Charset>>() {
            public SortedMap<String,Charset> run() {
                TreeMap<String,Charset> m =
                    new TreeMap<String,Charset>(
                        ASCIICaseInsensitiveComparator.CASE_INSENSITIVE_ORDER);
                put(standardProvider.charsets(), m);
                CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
                if (ecp != null)
                    put(ecp.charsets(), m);
                for (Iterator<CharsetProvider> i = providers(); i.hasNext();) {
                    CharsetProvider cp = i.next();
                    put(cp.charsets(), m);
                }
                return Collections.unmodifiableSortedMap(m);
            }
        });
}
 
Example #29
Source Project: TencentKona-8   Author: Tencent   File: Charset.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Iterator<CharsetProvider> providers() {
    return new Iterator<CharsetProvider>() {

            ClassLoader cl = ClassLoader.getSystemClassLoader();
            ServiceLoader<CharsetProvider> sl =
                ServiceLoader.load(CharsetProvider.class, cl);
            Iterator<CharsetProvider> i = sl.iterator();

            CharsetProvider next = null;

            private boolean getNext() {
                while (next == null) {
                    try {
                        if (!i.hasNext())
                            return false;
                        next = i.next();
                    } catch (ServiceConfigurationError sce) {
                        if (sce.getCause() instanceof SecurityException) {
                            // Ignore security exceptions
                            continue;
                        }
                        throw sce;
                    }
                }
                return true;
            }

            public boolean hasNext() {
                return getNext();
            }

            public CharsetProvider next() {
                if (!getNext())
                    throw new NoSuchElementException();
                CharsetProvider n = next;
                next = null;
                return n;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
}
 
Example #30
Source Project: TencentKona-8   Author: Tencent   File: Charset.java    License: GNU General Public License v2.0 4 votes vote down vote up
private static Charset lookupExtendedCharset(String charsetName) {
    CharsetProvider ecp = ExtendedProviderHolder.extendedProvider;
    return (ecp != null) ? ecp.charsetForName(charsetName) : null;
}