Package org.biojava.utils
Class FileAsList
java.lang.Object
java.util.AbstractCollection
java.util.AbstractList
org.biojava.utils.FileAsList
- All Implemented Interfaces:
Iterable
,Collection
,List
,SequencedCollection
,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
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsConstructorDescriptionFileAsList
(File mappedFile, boolean mutable) Creates a newFileAsList
instance from an existing backing file.FileAsList
(File mappedFile, int recordLength) Creates a newFileAsList
and corresponding backing file. -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
clear()
void
commit()
commit
commits pending changes.protected abstract void
generateRecord
(byte[] buffer, Object item) get
(int indx) abstract Comparator
iterator()
protected abstract 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.This always returns null, not the previous object.int
size()
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subList
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
addAll, addFirst, addLast, contains, containsAll, getFirst, getLast, isEmpty, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, sort, spliterator, toArray, toArray
-
Constructor Details
-
FileAsList
Creates a newFileAsList
and corresponding backing file.- Parameters:
mappedFile
- aFile
used to back the list. This file must not already exist.recordLength
- anint
byte record length.- Throws:
IOException
- if an error occurs.
-
FileAsList
Creates a newFileAsList
instance from an existing backing file.- Parameters:
mappedFile
- aFile
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.
-
-
Method Details
-
rawGet
rawGet
reads the record at the specified index as a raw byte array.- Parameters:
indx
- anint
list index.- Returns:
- a
byte []
array containing the raw record data.
-
get
- Specified by:
get
in interfaceList
- Specified by:
get
in classAbstractList
-
size
- Specified by:
size
in interfaceCollection
- Specified by:
size
in interfaceList
- Specified by:
size
in classAbstractCollection
-
add
- Specified by:
add
in interfaceCollection
- Specified by:
add
in interfaceList
- Overrides:
add
in classAbstractList
-
set
This always returns null, not the previous object.- Specified by:
set
in interfaceList
- Overrides:
set
in classAbstractList
-
clear
- Specified by:
clear
in interfaceCollection
- Specified by:
clear
in interfaceList
- Overrides:
clear
in classAbstractList
-
commit
Description copied from interface:Commitable
commit
commits pending changes.- Specified by:
commit
in interfaceCommitable
-
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. If the rollback fails, you must raise an AssertionFailure.- Specified by:
rollback
in interfaceCommitable
-
parseRecord
-
generateRecord
- Throws:
IOException
-
getComparator
-
iterator
- Specified by:
iterator
in interfaceCollection
- Specified by:
iterator
in interfaceIterable
- Specified by:
iterator
in interfaceList
- Overrides:
iterator
in classAbstractList
-