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, subList
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
public 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.List
get
in class java.util.AbstractList
public int size()
size
in interface java.util.Collection
size
in interface java.util.List
size
in class java.util.AbstractCollection
public boolean add(java.lang.Object o)
add
in interface java.util.Collection
add
in interface java.util.List
add
in class java.util.AbstractList
public java.lang.Object set(int indx, java.lang.Object o)
set
in interface java.util.List
set
in class java.util.AbstractList
public void clear()
clear
in interface java.util.Collection
clear
in interface java.util.List
clear
in class java.util.AbstractList
public void commit()
Commitable
commit
commits pending changes.commit
in interface Commitable
public void rollback()
Commitable
rollback
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 Commitable
protected abstract java.lang.Object parseRecord(byte[] buffer)
protected abstract void generateRecord(byte[] buffer, java.lang.Object item) throws java.io.IOException
java.io.IOException
public abstract java.util.Comparator getComparator()
public java.util.Iterator iterator()
iterator
in interface java.lang.Iterable
iterator
in interface java.util.Collection
iterator
in interface java.util.List
iterator
in class java.util.AbstractList