Class DbaseCodepage

java.lang.Object
org.gvsig.fmap.dal.store.dbf.utils.DbaseCodepage

public class DbaseCodepage extends Object
Reads and writes codepage (.cpg) files which are sometime used to externally specify the charset encoding of a DBF file.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final short[]
    Define the valid dbf Language driver IDs (equivalent to MSDOS code pages), which are used on the byte 29 of the DBF header to define the DBF codepage.
    static final String[]
    Equivalent Java charset names to the code pages defined in dbfLdid, using Java NIO Charset names (which differ from JAVA IO names, see https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Defines the dbfFile and constructs the name of the .cpg file based on it
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    cpg2java(String codePage)
     
     
    static String
    getCharsetName(int ldid)
    Gets the Java NIO charset name equivalent to the provided ldid value.
    static String
     
    static int
    getLdid(String charsetName)
    Gets the dbf Language driver IDs (code pages) corresponding to the provided charset name
    static String
    java2cpg(String charset)
     
    Reads the charset from the codepage file, and updates the internal charset definition
    void
    setCharset(String charset)
     
    void
    write(String charset)
    Writes the specified charset to the codepage file, and updates the internal charset definition

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • dbfLdid

      public static final short[] dbfLdid
      Define the valid dbf Language driver IDs (equivalent to MSDOS code pages), which are used on the byte 29 of the DBF header to define the DBF codepage. The equivalences of these charsets using Java NIO charset names are defined on the ldidJava array (so 0x01 is equivalent to IBM437, 0x02 to IBM850, etc) See some other equivalences in: https://github.com/infused/dbf/blob/master/docs/supported_encodings.csv https://github.com/olemb/dbfread/blob/master/dbfread/codepages.py https://joinup.ec.europa.eu/svn/gvsig-desktop/trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/dbf/DbfEncodings.java
    • ldidJava

      public static final String[] ldidJava
      Equivalent Java charset names to the code pages defined in dbfLdid, using Java NIO Charset names (which differ from JAVA IO names, see https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html)
  • Constructor Details

    • DbaseCodepage

      public DbaseCodepage(File dbfFile)
      Defines the dbfFile and constructs the name of the .cpg file based on it
  • Method Details

    • getCpgFileName

      public static String getCpgFileName(String dbfFile)
    • getCharset

      public String getCharset()
    • setCharset

      public void setCharset(String charset)
    • cpg2java

      public static String cpg2java(String codePage)
    • java2cpg

      public static String java2cpg(String charset)
    • read

      public String read()
      Reads the charset from the codepage file, and updates the internal charset definition
    • write

      public void write(String charset)
      Writes the specified charset to the codepage file, and updates the internal charset definition
    • getLdid

      public static int getLdid(String charsetName)
      Gets the dbf Language driver IDs (code pages) corresponding to the provided charset name
      Returns:
      The LDID code, or 0x00 if no equivalent LDID code was found for the provided charsetName
    • getCharsetName

      public static String getCharsetName(int ldid)
      Gets the Java NIO charset name equivalent to the provided ldid value. Gets null if the provided ldid is not recognised as a valid code