net.shredzone.ifish.db
Class NaviDb

java.lang.Object
  extended by net.shredzone.ifish.db.NaviDb
Direct Known Subclasses:
NaviDbTableModel

public class NaviDb
extends Object

This class contains the database, and is able to read and write the iRivNavi.iDB file, as well as synchronize with a directory.

Version:
$Id: NaviDb.java 291 2009-04-28 21:29:27Z shred $

Field Summary
protected  SortedSet<Entry> sEntries
           
 
Constructor Summary
NaviDb()
          Create an empty database.
NaviDb(File file, String charset)
          Create a database and fill it with a database file.
 
Method Summary
 void addEntry(Entry entry)
          Add an entry to the database.
 void exportFile(File file, String charset)
          Export this database to a database file.
 void exportFile(File file, String charset, StatusCallback cb)
          Export this database to a database file.
 int getAddCounter()
          Get the number of entries that have been added since last counter reset.
 Date getCreationDate()
          Get the creation date of this database.
 Entry getEntry(File file)
          Get the Entry for the given File.
 Entry getEntry(File base, String fname)
          Get the Entry for the given database filename (i.e. the jukebox' filename).
 int getRemoveCounter()
          Get the number of entries that have been removed since last counter reset.
 int getUpdateCounter()
          Get the number of entries that have been updated since last counter reset.
 void importFile(File file, String charset)
          Import a database file into this database.
 void importFile(File file, String charset, StatusCallback cb)
          Import a database file into this database.
 Iterator<Entry> iterator()
          Get an iterator of all entries.
 boolean knowsFile(File file)
          Check if a File is known by this database.
 boolean modifiedFile(File file)
          Check if a File has been modified after the current database has been written to the harddisk.
 void removeEntry(Entry entry)
          Remove an entry from the database.
 void resetCounters()
          Reset the add and remove counters.
 int size()
          Get the number of entries in this database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sEntries

protected final SortedSet<Entry> sEntries
Constructor Detail

NaviDb

public NaviDb()
Create an empty database.


NaviDb

public NaviDb(File file,
              String charset)
       throws IOException,
              DatabaseException,
              UnsupportedEncodingException
Create a database and fill it with a database file.

Parameters:
file - Database file to be read
charset - Desired Charset
Throws:
IOException - File was erraneous or could not be read
DatabaseException
UnsupportedEncodingException
Method Detail

addEntry

public void addEntry(Entry entry)
              throws DatabaseException
Add an entry to the database. If the entry does already exist (i.e. there is an Entry with the same file name), is will be replaced by the given entry (maybe having new tag attributes).

Parameters:
entry - Entry to be added
Throws:
DatabaseException

removeEntry

public void removeEntry(Entry entry)
Remove an entry from the database. If the entry does not exist, nothing will happen. The file on the harddisk that is connected to the Entry, will be kept untouched.

Parameters:
entry - Entry to be removed

resetCounters

public void resetCounters()
Reset the add and remove counters.


getAddCounter

public int getAddCounter()
Get the number of entries that have been added since last counter reset. This is useful if you want to write out some statistics after an import, export or sync operation.

Returns:
Number of entries added.

getUpdateCounter

public int getUpdateCounter()
Get the number of entries that have been updated since last counter reset. This is useful if you want to write out some statistics after an import, export or sync operation.

Returns:
Number of entries updated.

getRemoveCounter

public int getRemoveCounter()
Get the number of entries that have been removed since last counter reset. This is useful if you want to write out some statistics after an import, export or sync operation.

Returns:
Number of entries removed.

getCreationDate

public Date getCreationDate()
Get the creation date of this database.

Returns:
Creation date

knowsFile

public boolean knowsFile(File file)
Check if a File is known by this database. This is useful for database synchronisation.

Parameters:
file - File to be checked
Returns:
true: file is known to this database, false: unknown

getEntry

public Entry getEntry(File file)
Get the Entry for the given File. If there is no Entry for this file in the database, null will be returned.

Parameters:
file - File to be checked
Returns:
Entry to this file, or null

getEntry

public Entry getEntry(File base,
                      String fname)
Get the Entry for the given database filename (i.e. the jukebox' filename). If there is no Entry for this filename in the database, null will be returned.

Parameters:
base - The root of the jukebox directory
fname - Filename to be checked
Returns:
Entry to this file, or null

modifiedFile

public boolean modifiedFile(File file)
Check if a File has been modified after the current database has been written to the harddisk. This can be used to find out if a file needs to be updated in the database.

If the database was not read yet, then this method will always return true. If the file did not exist, this method will always return false.

Parameters:
file - File to be checked
Returns:
true: file was modified after DB creation. false: wasn't.

importFile

public void importFile(File file,
                       String charset)
                throws IOException,
                       DatabaseException,
                       UnsupportedEncodingException
Import a database file into this database.

Parameters:
file - Database file to be imported
charset - Charset the database is written in
Throws:
IOException
DatabaseException
UnsupportedEncodingException

importFile

public void importFile(File file,
                       String charset,
                       StatusCallback cb)
                throws IOException,
                       DatabaseException,
                       UnsupportedEncodingException
Import a database file into this database. This method automatically detects whether the database file was written in UTF-16 or in an old format. If the old format was detected, the given charset is used to decode the strings.

Parameters:
file - Database file to be imported
charset - Charset the database is written in
cb - StatusCallback to be used
Throws:
IOException
DatabaseException
UnsupportedEncodingException

exportFile

public void exportFile(File file,
                       String charset)
                throws IOException,
                       UnsupportedEncodingException
Export this database to a database file.

Parameters:
file - File to be written to.
charset - Charset to be used for export.
Throws:
IOException
UnsupportedEncodingException

exportFile

public void exportFile(File file,
                       String charset,
                       StatusCallback cb)
                throws IOException,
                       UnsupportedEncodingException
Export this database to a database file. If "UTF-16" is given as charset, the new database file format is used automatically.

Parameters:
file - File to be written to.
charset - Charset to be used for export.
cb - StatusCallback to be used.
Throws:
IOException
UnsupportedEncodingException

size

public int size()
Get the number of entries in this database.

Returns:
Number of entries

iterator

public Iterator<Entry> iterator()
Get an iterator of all entries.

Returns:
Iterator


Copyright © 2007-2011 shredzone.org. All Rights Reserved.