Holger's Java API

## com.antelmann.cddb
Class FileCDDB

    java.lang.Object
      com.antelmann.cddb.FileCDDB

All Implemented Interfaces:
  CDDB

    public class FileCDDB

extends Object
implements CDDB

FileCDDB is a local CD database that works off the file system.

The format under which the CD entries are stored is identical to the raw format of the online FreeDB.org service:
Each category is represented by a subdirectory from the base directory, and each CDinfo object is stored in a separate file named by the discID in the associated category.

For 'fuzzy' (or inexact) queries, the FileCDDB incorporates a FuzzyLookup table that - by convention of this implementation - is based on a file that resides in the base directory of the database and is named fuzzy.map

Author:
  Holger Antelmann
See Also:
  `FuzzyLookup`, `FreeDB`, `CDInfo`, `CDID.getDiscID()`

Field Summary
`static String` `FUZZY_MAP` location of the FuzzyLookup file relative to the base dir

Constructor Summary
`FileCDDB()` uses cddb.local.dir from `Settings.getProperty(String)` to determine the default directory
`FileCDDB(File directory)` uses the given directory as the basis for the file-based database

Method Summary
`MyFile` `getBaseDirectory()` returns the directory it uses to store/retrieve CD info
`String[]` `getCategories()` returns the available categories under which the CDInfo entries are stored - in accordance to the CDDB standard
`MyFile` `getFileHandle(CDDBRecord record)` returns the file handle corresponding to the given record (this file would contain the information read to construct the CDInfo object)
`int` `importCDInfoFromServer(CDID cd, CDDB server)` imports all information that can be retrieved from the CDDB server in regards to the given CD (including fuzzy matches).
`boolean` `isInDatabase(CDID cd)` returns true only if at least one matching valid CDInfo instance is available in the database
`CDDBRecord[]` `queryCD(CDID cd)` queries the database and returns an array of matches.
`CDInfo` `readCDInfo(CDDBRecord record)` returns a CDDBEntry instance
`CDDBRecord[]` `search(String pattern)` performs a full-text search on the database
`protected void` `storeFuzzyMatch(CDID cd, CDDBRecord[] similarEntries)` stores the given fuzzy matches in the embedded FuzzyLookup instance.
`int` `verifyDB()` verifies the entire content of the database and returns the number of available CDInfo instances if everything went smoothly.
`void` `writeCDInfo(CDInfo cdinfo)` Writes the given CDInfo object to a file as specified in the raw CDDB format.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### FUZZY_MAP

    public static final String FUZZY_MAP

  location of the FuzzyLookup file relative to the base dir

  See Also:
    Constant Field Values

Constructor Detail

### FileCDDB

    public FileCDDB()
             throws IOException

  uses cddb.local.dir from `Settings.getProperty(String)` to determine the default directory

  Throws:
    `IOException`
  See Also:
    `Settings.getProperty(String)`

### FileCDDB

    public FileCDDB(File directory)
             throws IOException

  uses the given directory as the basis for the file-based database

  Throws:
    `IOException`

Method Detail

### getBaseDirectory

    public MyFile getBaseDirectory()

  returns the directory it uses to store/retrieve CD info

### getCategories

    public String[] getCategories()

  Description copied from interface: `CDDB`
  returns the available categories under which the CDInfo entries are stored - in accordance to the CDDB standard

  Specified by:
    `getCategories` in interface `CDDB`

### readCDInfo

    public CDInfo readCDInfo(CDDBRecord record)
                      throws IOException,
                             CDDBProtocolException

  returns a CDDBEntry instance

  Specified by:
    `readCDInfo` in interface `CDDB`
  Throws:
    `IOException`
    `CDDBProtocolException`
  See Also:
    `CDDBEntry`

### getFileHandle

    public MyFile getFileHandle(CDDBRecord record)

  returns the file handle corresponding to the given record (this file would contain the information read to construct the CDInfo object)

  See Also:
    `readCDInfo(CDDBRecord)`

### writeCDInfo

    public void writeCDInfo(CDInfo cdinfo)
                     throws IOException

  Writes the given CDInfo object to a file as specified in the raw CDDB format.

  Specified by:
    `writeCDInfo` in interface `CDDB`
  Throws:
    `IOException` - among other reasons if the file entry already exists
  See Also:
    `CDInfo.getXmcdContent()`

### queryCD

    public CDDBRecord[] queryCD(CDID cd)
                         throws IOException,
                                CDDBProtocolException

  Description copied from interface: `CDDB`
  queries the database and returns an array of matches. These matches can be exact matches as well as inexact matches, which can be determined by calling `isExactMatch()` on any returned element.

  Specified by:
    `queryCD` in interface `CDDB`
  Throws:
    `IOException`
    `CDDBProtocolException`
  See Also:
    `CDDBRecord.isExactMatch()`

### isInDatabase

    public boolean isInDatabase(CDID cd)
                         throws IOException,
                                CDDBProtocolException

  returns true only if at least one matching valid CDInfo instance is available in the database

  Throws:
    `IOException`
    `CDDBProtocolException`

### importCDInfoFromServer

    public int importCDInfoFromServer(CDID cd,
                                      CDDB server)
                               throws IOException,
                                      CDDBProtocolException

  imports all information that can be retrieved from the CDDB server in regards to the given CD (including fuzzy matches).

  Returns:
    the number of CDInfo objects imported; -1 is returned if the CD had already matching CDInfo objects locally
  Throws:
    `IOException`
    `CDDBProtocolException`

### storeFuzzyMatch

    protected void storeFuzzyMatch(CDID cd,
                                   CDDBRecord[] similarEntries)
                            throws IOException

  stores the given fuzzy matches in the embedded FuzzyLookup instance. This is done each time when inexact matches are imported into the database.

  Throws:
    `IOException`
  See Also:
    `importCDInfoFromServer(CDID, CDDB)`

### verifyDB

    public int verifyDB()
                 throws IOException,
                        XmcdFormatException

  verifies the entire content of the database and returns the number of available CDInfo instances if everything went smoothly. This method simply checks whether every file within the database directory is a valid readable file that can be parsed by the CDDBEntry class. The file for the fuzzy map is ignored.

  Throws:
    `IOException` - if a file could not be read
    `XmcdFormatException` - if a file could not be properly parsed

### search

    public CDDBRecord[] search(String pattern)
                        throws IOException

  performs a full-text search on the database

  Throws:
    `IOException`

(c) Holger Antelmann since 2001- all rights reserved (contact: info@antelmann.com)
see www.antelmann.com/developer for further details and available downloads