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

eu.vitaliy.pl.charset.DOSCharsetProvider Maven / Gradle / Ivy

Go to download

Java implementation of Mazovia encoding. Mazovia encoding is used under MS-DOS to represent Polish texts. Basically it is code page 437 with some positions filled with Polish letters.

The newest version!
package eu.vitaliy.pl.charset;

import java.nio.charset.Charset;
import java.nio.charset.spi.CharsetProvider;
import java.util.*;

/**
 *
 * @author  Vitaliy Oliynyk
 */
public class DOSCharsetProvider extends CharsetProvider {

    public static final String MAZOVIA_CHARSET_NAME = "mazovia";
    public static final String LATIN_2_CHARSET_NAME = "cp-852";
    public final static String[] MAZOVIA_ALIASES = new String[]{
        "cp-896",
        "cp896",
        "cp620",
        "cp-620",
        "cp790",
        "cp-790"
    };
    private static List charsets;

    @Override
    public Iterator charsets() {
        if (charsets == null || charsets.isEmpty()) {
            charsets = new ArrayList(2);
            charsets.add(new MazoviaCharset(MAZOVIA_CHARSET_NAME, MAZOVIA_ALIASES));
            charsets.add(new IBMLatinCharset(LATIN_2_CHARSET_NAME, null));
        }

        return charsets.iterator();
    }

    @Override
    public Charset charsetForName(String charsetName) {

        if(MAZOVIA_CHARSET_NAME.equalsIgnoreCase(charsetName)){
            return new MazoviaCharset(MAZOVIA_CHARSET_NAME, MAZOVIA_ALIASES);
        }

        List mazoviaList = Arrays.asList(MAZOVIA_ALIASES);

        if (mazoviaList.contains(charsetName.toLowerCase().trim())) {
            return new MazoviaCharset(MAZOVIA_CHARSET_NAME, MAZOVIA_ALIASES);
        } else if (charsetName.trim().equalsIgnoreCase(LATIN_2_CHARSET_NAME)) {
            return new IBMLatinCharset(LATIN_2_CHARSET_NAME, null);
        } else {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy