Package org.biojava.utils
Class FileAsList
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList
org.biojava.utils.FileAsList
- All Implemented Interfaces:
Iterable,Collection,List,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 newFileAsListinstance from an existing backing file.FileAsList(File mappedFile, int recordLength) Creates a newFileAsListand corresponding backing file. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidclear()voidcommit()commitcommits pending changes.protected abstract voidgenerateRecord(byte[] buffer, Object item) get(int indx) abstract Comparatoriterator()protected abstract ObjectparseRecord(byte[] buffer) byte[]rawGet(int indx) rawGetreads the record at the specified index as a raw byte array.voidrollback()rollbackreverses pending changes to restore initial (or prior commit) state.This always returns null, not the previous object.intsize()Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, subListMethods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Constructor Details
-
FileAsList
Creates a newFileAsListand corresponding backing file.- Parameters:
mappedFile- aFileused to back the list. This file must not already exist.recordLength- anintbyte record length.- Throws:
IOException- if an error occurs.
-
FileAsList
Creates a newFileAsListinstance from an existing backing file.- Parameters:
mappedFile- aFileused 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
rawGetreads the record at the specified index as a raw byte array.- Parameters:
indx- anintlist index.- Returns:
- a
byte []array containing the raw record data.
-
get
- Specified by:
getin interfaceList- Specified by:
getin classAbstractList
-
size
- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceList- Specified by:
sizein classAbstractCollection
-
add
- Specified by:
addin interfaceCollection- Specified by:
addin interfaceList- Overrides:
addin classAbstractList
-
set
This always returns null, not the previous object.- Specified by:
setin interfaceList- Overrides:
setin classAbstractList
-
clear
- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceList- Overrides:
clearin classAbstractList
-
commit
Description copied from interface:Commitablecommitcommits pending changes.- Specified by:
commitin interfaceCommitable
-
rollback
Description copied from interface:Commitablerollbackreverses 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:
rollbackin interfaceCommitable
-
parseRecord
-
generateRecord
- Throws:
IOException
-
getComparator
-
iterator
- Specified by:
iteratorin interfaceCollection- Specified by:
iteratorin interfaceIterable- Specified by:
iteratorin interfaceList- Overrides:
iteratorin classAbstractList
-