: Class jdbm

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.w3c.tools.dbm
Class jdbm

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

public class jdbm
extends java.lang.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.

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

Constructor Summary
`jdbm(java.io.File file)`

Method Summary
`protected int` | `allocateSpace(int size)` Allocate space in the file.
`void` | `close()`
`boolean` | `delete(byte[] key)` Delete the association for the provided key.
`boolean` | `delete(java.lang.String key)` Delete the association for the provided String key.
`java.util.Enumeration` | `elements()` Enumerate the elements of the database.
`static byte[]` | `getBytes(java.lang.String str)`
`protected boolean` | `getNextBucket(org.w3c.tools.dbm.jdbmEnumerator enum)` Update this enumeration current bucket to the next one.
`java.util.Enumeration` | `keys()` Enumerate the keys of this database.
`protected org.w3c.tools.dbm.LRUEntry` | `loadBucket(int fileptr)` Load the bucket whose file pointer is given.
`byte[]` | `lookup(byte[] key)` Lookup the value associated with the provided key.
`byte[]` | `lookup(java.lang.String key)` Lookup the value associated to the given String key.
`static void` | `main(java.lang.String[] args)`
`void` | `printAvail(java.io.PrintStream out)` Print the list of available blocks:
`void` | `printHeader(java.io.PrintStream out)` Print various database options to the given stream.
`jdbm` | `reorganize(boolean trace)` Return a clean instance of that database, after reorganization.
`void` | `save()` Save thisdatabase to disk.
`void` | `store(byte[] key, byte[] value, int mode)` Store the given association of key/value.
`protected void` | `trace(java.lang.String msg)`
`protected org.w3c.tools.dbm.jdbmBucket` | `unloadBucket()` Select a bucket to be removed from the cache, unload it.
`protected int` | `write(org.w3c.tools.dbm.jdbmBucket bucket, byte[] key, byte[] data)` Allocate and write the provided key/value.

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

Field Detail

### STORE_REPLACE

    public static final int STORE_REPLACE

  Mode for store - Replace any existing entry with the new provided one.

### STORE_INSERT

    public static final int STORE_INSERT

  Mode for store - Only insert this element if it is not already defined.

### BLOCK_SIZE

    protected static final int BLOCK_SIZE

### DIR_BITS

    protected static final int DIR_BITS

  Default directory bits for this database.

### CACHE_SIZE

    protected static final int CACHE_SIZE

  Default cache size.

Constructor Detail

### jdbm

    public jdbm(java.io.File file)
         throws java.io.IOException

Method Detail

### trace

    protected final void trace(java.lang.String msg)

### printHeader

    public void printHeader(java.io.PrintStream out)

  Print various database options to the given stream.
  Parameters:
    `out` - The PrintStream to display info to.

### printAvail

    public void printAvail(java.io.PrintStream out)

  Print the list of available blocks:
  Parameters:
    `out` - The print stream to print to.

### 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.

### write

    protected int write(org.w3c.tools.dbm.jdbmBucket bucket,
                        byte[] key,
                        byte[] data)
                 throws java.io.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.

### unloadBucket

    protected org.w3c.tools.dbm.jdbmBucket unloadBucket()
                                                 throws java.io.IOException

  Select a bucket to be removed from the cache, unload it.
  Returns:
    A bucket ready to be reused.

### loadBucket

    protected org.w3c.tools.dbm.LRUEntry loadBucket(int fileptr)
                                             throws java.io.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).

### store

    public void store(byte[] key,
                      byte[] value,
                      int mode)
               throws java.io.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...

### lookup

    public byte[] lookup(byte[] key)
                  throws java.io.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.

### lookup

    public byte[] lookup(java.lang.String key)
                  throws java.io.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.

### delete

    public boolean delete(byte[] key)
                   throws java.io.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.

### delete

    public boolean delete(java.lang.String key)
                   throws java.io.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.

### save

    public void save()
              throws java.io.IOException

  Save thisdatabase to disk.

### getNextBucket

    protected boolean getNextBucket(org.w3c.tools.dbm.jdbmEnumerator enum)
                             throws java.io.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.

### keys

    public java.util.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.

### elements

    public java.util.Enumeration elements()

  Enumerate the elements of the database. This method has the same limitations then it's `keys` counterpart.
  Returns:
    An enumeration instance.

### close

    public void close()
               throws java.io.IOException

### 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.

### getBytes

    public static byte[] getBytes(java.lang.String str)

### main

    public static void main(java.lang.String[] args)
                     throws java.lang.Exception

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD