All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.w3c.tools.dbm.jdbm

java.lang.Object
   |
   +----org.w3c.tools.dbm.jdbm

public class jdbm
extends Object
An dbm like database in Java. This database is a transcription of what I have understood of gdbm into Java. Some of the code here I don't understand, but it looks like it works.


Variable Index

 o BLOCK_SIZE
 o CACHE_SIZE
Default cache size.
 o DIR_BITS
Default directory bits for this database.
 o STORE_INSERT
Mode for store - Only insert this element if it is not already defined.
 o STORE_REPLACE
Mode for store - Replace any existing entry with the new provided one.

Constructor Index

 o jdbm(File)
 o jdbm(String)
Opens a database file in the specified O_ mode.

Method Index

 o allocateSpace(int)
Allocate space in the file.
 o delete(byte[])
Delete the association for the provided key.
 o delete(String)
Delete the association for the provided String key.
 o elements()
Enumerate the elements of the database.
 o fetch(byte[])
Fetch the data if the given key exists in the data base
 o fetch(String)
Fetch the data if the given key exists in the data base
 o fetchBytes(String)
Fetch the data if the given key exists in the data base
 o fetchString(byte[])
Fetch the data if the given key exists in the data base
 o getBytes(String)
 o getNextBucket(jdbmEnumerator)
Update this enumeration current bucket to the next one.
 o keys()
Enumerate the keys of this database.
 o loadBucket(int)
Load the bucket whose file pointer is given.
 o lookup(byte[])
Lookup the value associated with the provided key.
 o lookup(String)
Lookup the value associated to the given String key.
 o main(String[])
 o printAvail(PrintStream)
Print the list of available blocks:
 o printHeader(PrintStream)
Print various database options to the given stream.
 o reorganize(boolean)
Return a clean instance of that database, after reorganization.
 o save()
Save thisdatabase to disk.
 o store(byte[], byte[], int)
Store the given association of key/value.
 o store(String, byte[], int)
Store the data for the given key in the specified S_ mode.
 o store(String, String, int)
Store the data for the given key in the specified S_ mode.
 o trace(String)
 o unloadBucket()
Select a bucket to be removed from the cache, unload it.
 o write(jdbmBucket, byte[], byte[])
Allocate and write the provided key/value.

Variables

 o STORE_REPLACE
 public static final int STORE_REPLACE
Mode for store - Replace any existing entry with the new provided one.

 o STORE_INSERT
 public static final int STORE_INSERT
Mode for store - Only insert this element if it is not already defined.

 o BLOCK_SIZE
 protected static final int BLOCK_SIZE
 o DIR_BITS
 protected static final int DIR_BITS
Default directory bits for this database.

 o CACHE_SIZE
 protected static final int CACHE_SIZE
Default cache size.

Constructors

 o jdbm
 public jdbm(String filename) throws IOException
Opens a database file in the specified O_ mode.

Parameters:
filename - the database file name.
Throws: IOException
if a problem with the file occurs
 o jdbm
 public jdbm(File file) throws IOException

Methods

 o trace
 protected final void trace(String msg)
 o printHeader
 public void printHeader(PrintStream out)
Print various database options to the given stream.

Parameters:
out - The PrintStream to display info to.
 o printAvail
 public void printAvail(PrintStream out)
Print the list of available blocks:

Parameters:
out - The print stream to print to.
 o allocateSpace
 protected int allocateSpace(int size)
Allocate space in the file.

Parameters:
size - The size of the file block we want.
Returns:
The file pointer to the allocated block.
 o write
 protected int write(jdbmBucket bucket,
                     byte key[],
                     byte data[]) throws IOException
Allocate and write the provided key/value. This is a short end for writing new associations to the file.

Parameters:
bucket - Suggested bucket to allocate data from.
key - The key part of the item to write.
data - The data part of the item to write.
Returns:
The file position of the written element.
 o unloadBucket
 protected synchronized jdbmBucket unloadBucket() throws IOException
Select a bucket to be removed from the cache, unload it.

Returns:
A bucket ready to be reused.
 o loadBucket
 protected synchronized LRUEntry loadBucket(int fileptr) throws IOException
Load the bucket whose file pointer is given.

Parameters:
fileptr - The file pointer of the bucket to be loaded.
into - The bucket to resue (or null).
 o store
 public void store(byte key[],
                   byte value[],
                   int mode) throws IOException
Store the given association of key/value.

Parameters:
key - The bytes that makes the key.
value - The bytes that makes the value.
mode - The mode of the storing, can be...
 o store
 public void store(String key,
                   byte data[],
                   int mode) throws IOException
Store the data for the given key in the specified S_ mode.

Parameters:
key - the bytes of the key.
data - the bytes of the key.
mode - the S_ mode.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o store
 public void store(String key,
                   String data,
                   int mode) throws IOException
Store the data for the given key in the specified S_ mode.

Parameters:
key - the bytes of the key.
data - the bytes of the key.
mode - the S_ mode.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o lookup
 public byte[] lookup(byte key[]) throws IOException
Lookup the value associated with the provided key.

Parameters:
key - The bits of the key to look for.
Returns:
The bits that makes the associated value, or null if not found.
 o lookup
 public byte[] lookup(String key) throws IOException
Lookup the value associated to the given String key.

Parameters:
key - The string that we are looking for.
Returns:
The bits that makes the associated value, or null if not found.
 o fetch
 public byte[] fetch(byte key[]) throws IOException
Fetch the data if the given key exists in the data base

Parameters:
key - the bytes of the key.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o fetch
 public String fetch(String key) throws IOException
Fetch the data if the given key exists in the data base

Parameters:
key - the bytes of the key.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o fetchBytes
 public byte[] fetchBytes(String key) throws IOException
Fetch the data if the given key exists in the data base

Parameters:
key - the bytes of the key.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o fetchString
 public String fetchString(byte key[]) throws IOException
Fetch the data if the given key exists in the data base

Parameters:
key - the bytes of the key.
Returns:
the data bytes stored for the key.
Throws: IOException
for whatever
 o delete
 public boolean delete(byte key[]) throws IOException
Delete the association for the provided key.

Parameters:
key - The key of the element to remove.
Returns:
A boolean true if deletion was succesfull.
 o delete
 public boolean delete(String key) throws IOException
Delete the association for the provided String key.

Parameters:
key - The key of the element to remove.
Returns:
A boolean true if deletion was succesfull.
 o save
 public void save() throws IOException
Save thisdatabase to disk.

 o getNextBucket
 protected boolean getNextBucket(jdbmEnumerator enum) throws IOException
Update this enumeration current bucket to the next one.

Parameters:
enum - The current enumeration state.
Returns:
A boolean true if the end of the database has been reached, falseotherwise.
 o keys
 public Enumeration keys()
Enumerate the keys of this database. This method will retun an enumeration object suitable to walk through all the keys of the database. You are not guaranteed that the enumerator will not enumerate the same key multiple time.

You are guaranteed, however that you will walk at least once through all the keys that were present at the time you created the enumeration (but not through the one that were deleted while you are walking through the database).

Returns:
An enumeration instance.
 o elements
 public Enumeration elements()
Enumerate the elements of the database. This method has the same limitations then it's keys counterpart.

Returns:
An enumeration instance.
 o reorganize
 public jdbm reorganize(boolean trace)
Return a clean instance of that database, after reorganization. Of course, no accesses should me made to the current database while cleaning it up. Note that this returns a new instance of the database !

Returns:
A clean database, or null if the reorganization failed.
 o getBytes
 public static byte[] getBytes(String str)
 o main
 public static void main(String args[]) throws Exception

All Packages  Class Hierarchy  This Package  Previous  Next  Index