All Downloads are FREE. Search and download functionalities are using the official Maven repository.

webit.script.util.EncodingPool Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
// Copyright (c) 2013, Webit Team. All Rights Reserved.
package webit.script.util;

import java.nio.charset.Charset;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author Zqq
 */
public class EncodingPool {

    private final static ConcurrentHashMap cache = new ConcurrentHashMap();
    public final static String UTF_8;

    static {
        UTF_8 = intern("UTF-8");
    }

    public static String intern(final String encoding) {
        String acn;
        if ((acn = cache.get(encoding)) == null) {
            try {
                acn = Charset.forName(encoding).name();
            } catch (Exception e) {
                acn = encoding;
            }
            acn = acn.intern();
            String old = cache.putIfAbsent(encoding, acn);
            if (old != null) {
                acn = old;
            }
        }
        return acn;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy