Enum DBFFileCodePage

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<DBFFileCodePage>

    public enum DBFFileCodePage
    extends java.lang.Enum<DBFFileCodePage>
    Enum that represents Code Pages supported by DBF files. This enum is a matrix that maps DBF single-byte code page mark into JVM's equivalent Charset.

    This matrix was written by hand using several sources including:

      - Wikipedia entries to find Code Page aliases
      - Java's supported Charsets list https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
      - DBF specs
     
    Each enum entry comprehends the next fields:
    • Code Page: A publicly-known Code Page e.g. 437, 850, 1252
    • Platform name: Free text that helps identifying the code page platform (this is not based on any standard)
    • Code Page Mark(s): A single-byte which value is found inside the DBF's header (at the 29th byte of the DBF stream). This code page mark byte is completely arbitrary, and has no meaning outside of DBF's world. Although DBF supports only one single-byte as the code page mark, there are some code page marks that map back to the same DBFFileCodePage enum item; for example, 0X01 and 0X18 code page marks both point back to code page 437.
    • Charset alias(es): Optionally, each code page might have publicly-known charset aliases (some of them backed by standards, other's by OS platform, others by Java, etc.). These aliases can be used to help the JVM mapping back to the Charset impl. For example, "US-ASCII" is an alias for code page 20127, "Shift_JIS" is an alias for code page 932, "cp667" is an alias for code page 620

    • Method Detail

      • values

        public static DBFFileCodePage[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (DBFFileCodePage c : DBFFileCodePage.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DBFFileCodePage valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • fromCodePageMark

        public static DBFFileCodePage fromCodePageMark​(byte codePageMark)
      • fromCharsetName

        public static DBFFileCodePage fromCharsetName​(java.lang.String charsetName)
      • fromCodePage

        public static DBFFileCodePage fromCodePage​(int codePage)
      • getCodePage

        public int getCodePage()
        Retrieves the publicly-known Code Page numeric value associated with this platform
        Returns:
        the value assigned to this platform's Code Page.
      • getPlatform

        public java.lang.String getPlatform()
        Retrieves the platform name.
        Returns:
        a text representing the platform name.
      • getCodePageMarks

        public byte[] getCodePageMarks()
        Retrieves an array representing each of the Code Page Mark bytes that might represent this platform. The retrieved array might be empty.
        Returns:
        an array with each individual byte that maps to this platform.
      • getCharsetAliases

        public java.lang.String[] getCharsetAliases()
        Retrieves an array with each publicly-known alias for this platform that might be used by the JVM to map this into a Charset instance by the toCharset() method.
        Returns:
        all possible aliases that might be found by the JVM to load a Charset, including the computed alias for Code Page ("cpXXX" where XXX is a Code Page number)
      • toCharset

        public java.nio.charset.Charset toCharset()
        Maps this platform's Code Page to a JVM's Charset instance, making an exhaustive search using all known aliases.
        Returns:
        a Charset instance, if the running JVM contains a Charset that can be mapped back.
        Throws:
        java.nio.charset.UnsupportedCharsetException - if the JVM could not find any mapping for a Charset