Package de.jungblut.datastructure
Class DiskList<E extends org.apache.hadoop.io.Writable>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- de.jungblut.datastructure.DiskList<E>
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>
public final class DiskList<E extends org.apache.hadoop.io.Writable> extends java.util.AbstractList<E> implements java.lang.Iterable<E>, java.lang.AutoCloseable, java.io.CloseableA file backed disk for adding elements and reading from them in a sequential fashion.- Author:
- thomas.jungblut
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDiskList.IORuntimeException
-
Constructor Summary
Constructors Constructor Description DiskList(java.lang.String path)Opens a new disk list at the given path.DiskList(java.lang.String path, int bufferSize)Opens a new disk list at the given path with the given buffersize.DiskList(java.lang.String path, int bufferSize, E reusableElement)Opens a new disk list at the given path with the given buffersize.DiskList(java.lang.String path, E reusableElement)Opens a new disk list at the given path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E element)Writes the given element to the disk.voidclose()Closes read and write, also deletes the file.Eget(int index)de.jungblut.datastructure.DiskList.StategetCurrentState()java.util.Iterator<E>iterator()voidopenRead()Opens for a read, closes the write implicitly.Epoll(E element)Polls the next element from the input stream.intsize()-
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, remove, removeRange, set, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
-
-
-
-
Constructor Detail
-
DiskList
public DiskList(java.lang.String path) throws java.io.IOExceptionOpens a new disk list at the given path. Buffered through a 8kBufferedOutputStream.- Throws:
java.io.IOException
-
DiskList
public DiskList(java.lang.String path, int bufferSize) throws java.io.IOExceptionOpens a new disk list at the given path with the given buffersize. 64k seems quite optimal for most normal hard disks. With 7.2k rpm disk and enough cache 512k might also be optimal.- Throws:
java.io.IOException
-
DiskList
public DiskList(java.lang.String path, E reusableElement) throws java.io.IOExceptionOpens a new disk list at the given path. Buffered through a 8kBufferedOutputStream.
You can add a reusable element, that will be filled. This is certainly required when using an iterator.- Throws:
java.io.IOException
-
DiskList
public DiskList(java.lang.String path, int bufferSize, E reusableElement) throws java.io.IOExceptionOpens a new disk list at the given path with the given buffersize. 64k seems quite optimal for most normal hard disks. With 7.2k rpm disk and enough cache 512k might also be optimal. You can add a reusable element, that will be filled. This is certainly required when using an iterator.- Throws:
java.io.IOException
-
-
Method Detail
-
add
public boolean add(E element)
Writes the given element to the disk. Throws aDiskList.IORuntimeExceptionin case of IO failure.
-
openRead
public void openRead() throws java.io.IOExceptionOpens for a read, closes the write implicitly.- Throws:
java.io.IOException
-
poll
public E poll(E element) throws java.io.IOException
Polls the next element from the input stream.- Parameters:
element- the element to fill.- Returns:
- the same element as passed through the parameter, just filled with information. Null if there is nothing more to read.
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOExceptionCloses read and write, also deletes the file.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
getCurrentState
public de.jungblut.datastructure.DiskList.State getCurrentState()
- Returns:
- the current state READ or WRITE.
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E extends org.apache.hadoop.io.Writable>- Specified by:
sizein interfacejava.util.List<E extends org.apache.hadoop.io.Writable>- Specified by:
sizein classjava.util.AbstractCollection<E extends org.apache.hadoop.io.Writable>- Returns:
- how many items were inserted.
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<E extends org.apache.hadoop.io.Writable>- Specified by:
iteratorin interfacejava.lang.Iterable<E extends org.apache.hadoop.io.Writable>- Specified by:
iteratorin interfacejava.util.List<E extends org.apache.hadoop.io.Writable>- Overrides:
iteratorin classjava.util.AbstractList<E extends org.apache.hadoop.io.Writable>
-
-