|
RAFoRandomAccessFile for Objects |
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--com.linxpda.raf.RAFo
This class reads and writes Java™ Objects to a local file, using String keys to reference objects stored. It maintains an in-memory index of file keys for faster reading and writing operations.
A typical ObjectFile session would go:
import com.linxpda.raf.*;
import java.util.Date;
public class FileTest {
public FileTest(String filename) {
try {
RAFo file = new RAFo(filename);
Date data = new Date();
file.insertObject("created", date);
file.insertObject("created-by", "Tom Cole");
//update a record
file.updateObject("created-by", "Sid Thomas");
//delete a record
file.removeObject("created-by");
Date date = (Date) file.getObject("created");
System.out.println("File created: " + date.toGMTString());
file.close();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
catch(RAFException dbe) {
dbe.printStackTrace();
}
catch(ClassNotFoundException cnfe) {
cbfe.printStackTrace();
}
finally {
System.exit(0);
}
}
public static void main(String args[]) {
if (args.length != 1) {
System.out.println("USEAGE: java FileTest ");
System.exit(0);
}
else {
new FileTest(args[0]);
}
}
}
| Constructor Summary | |
RAFo(java.lang.String filename)
Convenience constructor that attempts to open an existing file with the given filename, if that fails then a new file is created. |
|
RAFo(java.lang.String filename,
int initialCapacity)
Creates a new data file. |
|
RAFo(java.lang.String filename,
java.lang.String accessFlags)
Opens an existing database and provides access restrictions as per the access parameter. |
|
| Method Summary | |
void |
close()
Closes the data file and removes the header index from memory. |
boolean |
containsKey(java.lang.String key)
Denotes whether the specified String key points to an object in the file. |
java.util.Enumeration |
getKeys()
Returns an enumeration of all the keys currently referencing objects in the file. |
java.lang.Object |
getObject(java.lang.String key)
Returns the object in the file referenced by the supplied key. |
int |
getObjectCount()
Returns the total number of objects currently stored in the file. |
void |
insertObject(java.lang.String key,
java.lang.Object value)
Add the specified to the file, referencing it with the supplied key. |
void |
removeObject(java.lang.String key)
Removes the object referenced by key from the file. |
void |
updateObject(java.lang.String key,
java.lang.Object value)
Replaces the object referred to by key with the new object specified. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public RAFo(java.lang.String filename)
throws java.io.IOException,
RAFException
filename - The filename of the file to open or create.java.io.IOException - upon a system level access violationRAFException - if unable to open or create the file
public RAFo(java.lang.String filename,
int initialCapacity)
throws java.io.IOException,
RAFException
filename - Filename for the new data file.initialSize - The amount of space allocated for the
index header. May increase/decrease as needed. Provided for efficiency.java.io.IOException - upon receipt of a file writing error.RAFException - if the specified file already exists.
public RAFo(java.lang.String filename,
java.lang.String accessFlags)
throws java.io.IOException,
RAFException
filename - The data file to open.access - Access flags denoting file permissions. May be
'r' for read-only, 'w' for write-only or 'rw' for read & write permissions.java.io.IOException - upon receipt of a file I/O error.RAFException - if the specified file does not exist.| Method Detail |
public java.util.Enumeration getKeys()
public int getObjectCount()
public boolean containsKey(java.lang.String key)
key - The String key to look for.
public void insertObject(java.lang.String key,
java.lang.Object value)
throws java.io.IOException,
RAFException
key - The string key to use for referencing the object.object - The object to store.java.io.IOException - upon a file I/O error.RAFException - Upon a serialization or file access error.
public void updateObject(java.lang.String key,
java.lang.Object value)
throws java.io.IOException,
RAFException
key - The key for the object to replace.object - The new object to store.java.io.IOException - upon a file I/O error.RAFException - upon a file access or serialization error.
public void removeObject(java.lang.String key)
throws java.io.IOException,
RAFException
key - The key for the object to delete.java.io.IOException - upon a file I/O error.RAFException - upon a file access violation.
public java.lang.Object getObject(java.lang.String key)
throws java.io.IOException,
java.lang.ClassNotFoundException,
RAFException
key - The key for the file to retrieve.java.io.IOException - upon a file I/O error.RAFException - if the specified key does not exist, or if
a file access violation has occured.java.lang.ClassNotFoundException - if the class file for the read file cannot be found.
public void close()
throws java.io.IOException,
RAFException
|
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||