org.norther.tammi.acorn.io
Class RecordAccessFile

java.lang.Object
  extended by org.norther.tammi.acorn.io.RecordAccessFile

public class RecordAccessFile
extends Object

A record oriented RandomAccessFile.

Author:
Ilkka Priha

Nested Class Summary
protected static class RecordAccessFile.RecordHeader
          A header for records.
 
Field Summary
static int DEFAULT_CAPACITY
          The default capcacity.
static int DEFAULT_RECORD_LENGTH
          The default record length.
 
Constructor Summary
RecordAccessFile(File file, String mode)
          Constructs a record access file.
RecordAccessFile(File file, String mode, int capacity)
          Constructs a record access file, initializing the appropriate headers.
RecordAccessFile(File file, String mode, int capacity, int recordLength)
          Constructs a record access file, initializing the appropriate headers.
 
Method Summary
 void acquire()
          Acquires an exclusive lock to this record.
 void addRecord(String key, RecordWriter rec)
          Adds a new record.
 void clear()
          Clears the file.
 void close()
          Closes the file.
 boolean containsRecord(String key)
          Checks if there is a record with the given key.
 File getFile()
          Gets the file.
 RecordReader getRecord(String key)
          Gets a record.
 boolean getRecord(String key, RecordReader rec)
          Gets a record.
 Set keySet()
          Return the keys of all records in the file.
 void putRecord(String key, RecordWriter rec)
          Puts a record.
 int recordCount()
          Returns the number or records in the file.
 void release()
          Releases an exclusive lock to this record.
 boolean removeRecord(String key)
          Removes a record.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CAPACITY

public static final int DEFAULT_CAPACITY
The default capcacity.

See Also:
Constant Field Values

DEFAULT_RECORD_LENGTH

public static final int DEFAULT_RECORD_LENGTH
The default record length.

See Also:
Constant Field Values
Constructor Detail

RecordAccessFile

public RecordAccessFile(File file,
                        String mode)
                 throws IOException
Constructs a record access file.

Parameters:
file - the internal file.
mode - the access mode.
Throws:
IOException - on I/O errors.

RecordAccessFile

public RecordAccessFile(File file,
                        String mode,
                        int capacity)
                 throws IOException
Constructs a record access file, initializing the appropriate headers. Enough space is allocated in the index for the specified capacity.

Parameters:
file - the internal file.
mode - the access mode.
capacity - the initial capacity (0 = use default).
Throws:
IOException - on I/O errors.

RecordAccessFile

public RecordAccessFile(File file,
                        String mode,
                        int capacity,
                        int recordLength)
                 throws IOException
Constructs a record access file, initializing the appropriate headers. Enough space is allocated in the index for the specified capacity. The default record length is set to the specified value.

Parameters:
file - the internal file.
mode - the access mode.
capacity - the initial capacity (0 = use default).
recordLength - the default record length (0 = use default).
Throws:
IOException - on I/O errors.
Method Detail

getFile

public File getFile()
Gets the file.

Returns:
the file.

getRecord

public RecordReader getRecord(String key)
                       throws IOException
Gets a record.

Parameters:
key - the record key.
Returns:
a new record reader or null.
Throws:
IOException - on I/O errors.

getRecord

public boolean getRecord(String key,
                         RecordReader rec)
                  throws IOException
Gets a record.

Parameters:
key - the record key.
rec - a record reader.
Returns:
true if the record was found, otherwise false.
Throws:
IOException - on I/O errors.

putRecord

public void putRecord(String key,
                      RecordWriter rec)
               throws IOException
Puts a record.

Parameters:
key - the record key.
rec - a record writer.
Throws:
IOException - on I/O errors.

addRecord

public void addRecord(String key,
                      RecordWriter rec)
               throws IOException
Adds a new record.

Parameters:
key - the record key.
rec - a record writer.
Throws:
IOException - on I/O errors.

removeRecord

public boolean removeRecord(String key)
                     throws IOException
Removes a record.

Parameters:
key - the record key.
Returns:
true if the record was removed, otherwise false.
Throws:
IOException - on I/O errors.

keySet

public Set keySet()
Return the keys of all records in the file.

Returns:
a set of keys or an empty set.

recordCount

public int recordCount()
Returns the number or records in the file.

Returns:
the record count.

containsRecord

public boolean containsRecord(String key)
Checks if there is a record with the given key.

Parameters:
key - the record key.
Returns:
true if the record is found, otherwise false.

clear

public void clear()
           throws IOException
Clears the file.

Throws:
IOException - on I/O errors.

close

public void close()
           throws IOException
Closes the file.

Throws:
IOException - on I/O errors.

acquire

public void acquire()
Acquires an exclusive lock to this record.


release

public void release()
Releases an exclusive lock to this record.



Copyright © 2004 The Norther Organization. All rights reserved.