public abstract class FileAsList extends java.util.AbstractList implements Commitable
FileAsList creates a writable List
implementation backed by a random access file. There is a
restriction on the record length that the string representation of
that integer may not be longer than 4 bytes. This is because a
fixed 4 byte leader is used to encode the record length in the
file.| Constructor and Description |
|---|
FileAsList(java.io.File mappedFile,
boolean mutable)
Creates a new
FileAsList instance from an existing
backing file. |
FileAsList(java.io.File mappedFile,
int recordLength)
Creates a new
FileAsList and corresponding backing
file. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.lang.Object o) |
void |
clear() |
void |
commit()
commit commits pending changes. |
protected abstract void |
generateRecord(byte[] buffer,
java.lang.Object item) |
java.lang.Object |
get(int indx) |
abstract java.util.Comparator |
getComparator() |
java.util.Iterator |
iterator() |
protected abstract java.lang.Object |
parseRecord(byte[] buffer) |
byte[] |
rawGet(int indx)
rawGet reads the record at the specified index as
a raw byte array. |
void |
rollback()
rollback reverses pending changes to restore
initial (or prior commit) state. |
java.lang.Object |
set(int indx,
java.lang.Object o)
This always returns null, not the previous object.
|
int |
size() |
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subListaddAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitpublic FileAsList(java.io.File mappedFile,
int recordLength)
throws java.io.IOException
FileAsList and corresponding backing
file.mappedFile - a File used to back the
list. This file must not already exist.recordLength - an int byte record length.java.io.IOException - if an error occurs.public FileAsList(java.io.File mappedFile,
boolean mutable)
throws java.io.IOException
FileAsList instance from an existing
backing file.mappedFile - a File used to back the
list. This file must already exist.mutable - true if this list should support edits, false otherwisejava.io.IOException - if an error occurs.public byte[] rawGet(int indx)
rawGet reads the record at the specified index as
a raw byte array.indx - an int list index.byte [] array containing the raw record
data.public java.lang.Object get(int indx)
get in interface java.util.Listget in class java.util.AbstractListpublic int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollectionpublic boolean add(java.lang.Object o)
add in interface java.util.Collectionadd in interface java.util.Listadd in class java.util.AbstractListpublic java.lang.Object set(int indx,
java.lang.Object o)
set in interface java.util.Listset in class java.util.AbstractListpublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Listclear in class java.util.AbstractListpublic void commit()
Commitablecommit commits pending changes.commit in interface Commitablepublic void rollback()
Commitablerollback reverses pending changes to restore
initial (or prior commit) state. This always succededs or raises an
unchecked exception.
If the rollback fails, you must raise an AssertionFailure.rollback in interface Commitableprotected abstract java.lang.Object parseRecord(byte[] buffer)
protected abstract void generateRecord(byte[] buffer,
java.lang.Object item)
throws java.io.IOException
java.io.IOExceptionpublic abstract java.util.Comparator getComparator()
public java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class java.util.AbstractList