Package org.biojava.utils
Class FileAsList
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList
-
- org.biojava.utils.FileAsList
-
- All Implemented Interfaces:
java.lang.Iterable,java.util.Collection,java.util.List,Commitable
public abstract class FileAsList extends java.util.AbstractList implements Commitable
FileAsListcreates a writableListimplementation 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
Constructors Constructor Description FileAsList(java.io.File mappedFile, boolean mutable)Creates a newFileAsListinstance from an existing backing file.FileAsList(java.io.File mappedFile, int recordLength)Creates a newFileAsListand corresponding backing file.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.Object o)voidclear()voidcommit()commitcommits pending changes.protected abstract voidgenerateRecord(byte[] buffer, java.lang.Object item)java.lang.Objectget(int indx)abstract java.util.ComparatorgetComparator()java.util.Iteratoriterator()protected abstract java.lang.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.java.lang.Objectset(int indx, java.lang.Object o)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, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
FileAsList
public FileAsList(java.io.File mappedFile, int recordLength) throws java.io.IOExceptionCreates a newFileAsListand corresponding backing file.- Parameters:
mappedFile- aFileused to back the list. This file must not already exist.recordLength- anintbyte record length.- Throws:
java.io.IOException- if an error occurs.
-
FileAsList
public FileAsList(java.io.File mappedFile, boolean mutable) throws java.io.IOExceptionCreates 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:
java.io.IOException- if an error occurs.
-
-
Method Detail
-
rawGet
public byte[] rawGet(int indx)
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
public java.lang.Object get(int indx)
- Specified by:
getin interfacejava.util.List- Specified by:
getin classjava.util.AbstractList
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection- Specified by:
sizein interfacejava.util.List- Specified by:
sizein classjava.util.AbstractCollection
-
add
public boolean add(java.lang.Object o)
- Specified by:
addin interfacejava.util.Collection- Specified by:
addin interfacejava.util.List- Overrides:
addin classjava.util.AbstractList
-
set
public java.lang.Object set(int indx, java.lang.Object o)This always returns null, not the previous object.- Specified by:
setin interfacejava.util.List- Overrides:
setin classjava.util.AbstractList
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection- Specified by:
clearin interfacejava.util.List- Overrides:
clearin classjava.util.AbstractList
-
commit
public void commit()
Description copied from interface:Commitablecommitcommits pending changes.- Specified by:
commitin interfaceCommitable
-
rollback
public void 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
protected abstract java.lang.Object parseRecord(byte[] buffer)
-
generateRecord
protected abstract void generateRecord(byte[] buffer, java.lang.Object item) throws java.io.IOException- Throws:
java.io.IOException
-
getComparator
public abstract java.util.Comparator getComparator()
-
iterator
public java.util.Iterator iterator()
- Specified by:
iteratorin interfacejava.util.Collection- Specified by:
iteratorin interfacejava.lang.Iterable- Specified by:
iteratorin interfacejava.util.List- Overrides:
iteratorin classjava.util.AbstractList
-
-