Class DiskList<E extends org.apache.hadoop.io.Writable>

  • 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.Closeable
    A file backed disk for adding elements and reading from them in a sequential fashion.
    Author:
    thomas.jungblut
    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • 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
      boolean add​(E element)
      Writes the given element to the disk.
      void close()
      Closes read and write, also deletes the file.
      E get​(int index)  
      de.jungblut.datastructure.DiskList.State getCurrentState()  
      java.util.Iterator<E> iterator()  
      void openRead()
      Opens for a read, closes the write implicitly.
      E poll​(E element)
      Polls the next element from the input stream.
      int size()  
      • 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
      • 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.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Constructor Detail

      • DiskList

        public DiskList​(java.lang.String path)
                 throws java.io.IOException
        Opens a new disk list at the given path. Buffered through a 8k BufferedOutputStream.
        Throws:
        java.io.IOException
      • DiskList

        public DiskList​(java.lang.String path,
                        int bufferSize)
                 throws java.io.IOException
        Opens 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.IOException
        Opens a new disk list at the given path. Buffered through a 8k BufferedOutputStream.
        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.IOException
        Opens 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 a DiskList.IORuntimeException in case of IO failure.
        Specified by:
        add in interface java.util.Collection<E extends org.apache.hadoop.io.Writable>
        Specified by:
        add in interface java.util.List<E extends org.apache.hadoop.io.Writable>
        Overrides:
        add in class java.util.AbstractList<E extends org.apache.hadoop.io.Writable>
      • openRead

        public void openRead()
                      throws java.io.IOException
        Opens 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.IOException
        Closes read and write, also deletes the file.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.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:
        size in interface java.util.Collection<E extends org.apache.hadoop.io.Writable>
        Specified by:
        size in interface java.util.List<E extends org.apache.hadoop.io.Writable>
        Specified by:
        size in class java.util.AbstractCollection<E extends org.apache.hadoop.io.Writable>
        Returns:
        how many items were inserted.
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E extends org.apache.hadoop.io.Writable>
        Specified by:
        iterator in interface java.lang.Iterable<E extends org.apache.hadoop.io.Writable>
        Specified by:
        iterator in interface java.util.List<E extends org.apache.hadoop.io.Writable>
        Overrides:
        iterator in class java.util.AbstractList<E extends org.apache.hadoop.io.Writable>
      • get

        public E get​(int index)
        Specified by:
        get in interface java.util.List<E extends org.apache.hadoop.io.Writable>
        Specified by:
        get in class java.util.AbstractList<E extends org.apache.hadoop.io.Writable>