org.biojava.utils
Class FileAsList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.biojava.utils.FileAsList
- All Implemented Interfaces:
- Iterable, Collection, List, Commitable
public abstract class FileAsList
- extends 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.
- Author:
- Matthew Pocock, Keith James, Greg Cox
|
Constructor Summary |
FileAsList(File mappedFile,
boolean mutable)
Creates a new FileAsList instance from an existing
backing file. |
FileAsList(File mappedFile,
int recordLength)
Creates a new FileAsList and corresponding backing
file. |
| Methods inherited from class java.util.AbstractList |
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subList |
FileAsList
public FileAsList(File mappedFile,
int recordLength)
throws IOException
- Creates a new
FileAsList and corresponding backing
file.
- Parameters:
mappedFile - a File used to back the
list. This file must not already exist.recordLength - an int byte record length.
- Throws:
IOException - if an error occurs.
FileAsList
public FileAsList(File mappedFile,
boolean mutable)
throws IOException
- Creates a new
FileAsList instance from an existing
backing file.
- Parameters:
mappedFile - a File used to back the
list. This file must already exist.mutable - true if this list should support edits, false otherwise
- Throws:
IOException - if an error occurs.
rawGet
public byte[] rawGet(int indx)
rawGet reads the record at the specified index as
a raw byte array.
- Parameters:
indx - an int list index.
- Returns:
- a
byte [] array containing the raw record
data.
get
public Object get(int indx)
- Specified by:
get in interface List- Specified by:
get in class AbstractList
size
public int size()
- Specified by:
size in interface Collection- Specified by:
size in interface List- Specified by:
size in class AbstractCollection
add
public boolean add(Object o)
- Specified by:
add in interface Collection- Specified by:
add in interface List- Overrides:
add in class AbstractList
set
public Object set(int indx,
Object o)
- This always returns null, not the previous object.
- Specified by:
set in interface List- Overrides:
set in class AbstractList
clear
public void clear()
- Specified by:
clear in interface Collection- Specified by:
clear in interface List- Overrides:
clear in class AbstractList
commit
public void commit()
- Description copied from interface:
Commitable
commit commits pending changes.
- Specified by:
commit in interface Commitable
rollback
public void rollback()
- Description copied from interface:
Commitable
rollback reverses pending changes to restore
initial (or prior commit) state. This always succededs or raises an
unchecked exception.
- Specified by:
rollback in interface Commitable
parseRecord
protected abstract Object parseRecord(byte[] buffer)
generateRecord
protected abstract void generateRecord(byte[] buffer,
Object item)
throws IOException
- Throws:
IOException
getComparator
public abstract Comparator getComparator()
iterator
public Iterator iterator()
- Specified by:
iterator in interface Iterable- Specified by:
iterator in interface Collection- Specified by:
iterator in interface List- Overrides:
iterator in class AbstractList