/*
 *  @author Ranides Atterwim <ranides@gmail.com>
 *  @copyright Ranides Atterwim
 *  @license WTFPL
 *  @url http://ranides.net/projects/assira
 */

package net.ranides.assira.text;

import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import net.ranides.assira.annotations.Meta;
import net.ranides.assira.trace.AdvLogger;
import net.ranides.assira.trace.LoggerUtils;

/**
 *
 * @author ranides
 */

public final class TextEncoding {
    
    private static final AdvLogger LOGGER = LoggerUtils.getLogger();

    private TextEncoding() { }

    public static final Charset NIO_US_ASCII = Charset.forName("US-ASCII");

    public static final Charset NIO_ISO88591 = Charset.forName("ISO-8859-1");

    public static final Charset NIO_UTF8 = Charset.forName("UTF-8");

    public static final Charset NIO_UTF16BE = Charset.forName("UTF-16BE");

    public static final Charset NIO_UTF16LE = Charset.forName("UTF-16LE");

    public static final Charset NIO_UTF16 = Charset.forName("UTF-16");

    public static final Charset NIO_PL_DOS = Charset.forName("IBM852");

    public static final Charset NIO_PL_ISO = Charset.forName("ISO-8859-2");

    public static final Charset NIO_PL_WINDOWS = Charset.forName("windows-1250");

    public static final Charset NIO_MAZOVIA = load("mazovia");

    public static final Charset NIO_DEFAULT = Charset.defaultCharset();

    public static final String IO_US_ASCII = "ASCII";

    public static final String IO_ISO88591 = "ISO8859_1";

    public static final String IO_UTF8 = "UTF8";

    public static final String IO_UTF16BE = "UnicodeBigUnmarked";

    public static final String IO_UTF16LE = "UnicodeLittleUnmarked";

    public static final String IO_UTF16 = "UTF-16";

    public static final String IO_PL_DOS = "Cp852";

    public static final String IO_PL_ISO = "ISO8859_2";

    public static final String IO_PL_WINDOWS = "Cp1250";

    public static final String IO_MAZOVIA = "mazovia";

    public static final String IO_DEFAULT = Charset.defaultCharset().name();

    @Meta.Unsafe
    private static Charset load(String name) {
        try {
            return Charset.forName(name);
        } catch(UnsupportedCharsetException _cause) {
            LOGGER.finfo("Optional support for charset '%s': DISABLED", name);
            return null;
        }
    }
}
