Class FileIterator<T>

java.lang.Object
org.snpeff.fileIterator.FileIterator<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>
Direct Known Subclasses:
FastaFileIterator, LineClassFileIterator, LineFileIterator, MarkerFileIterator, PedFileIterator, SamFileIterator

public abstract class FileIterator<T> extends Object implements Iterable<T>, Iterator<T>
Opens a file and iterates over all objects in the file Note: The file is not loaded in memory, thus allows to iterate over very large files
Author:
pcingola
  • Field Details

    • debug

      protected boolean debug
    • verbose

      protected boolean verbose
    • autoClose

      protected boolean autoClose
    • countNewLineChars

      protected int countNewLineChars
    • lineNum

      protected int lineNum
    • next

      protected T next
    • reader

      protected BufferedReader reader
    • fileName

      protected String fileName
    • line

      protected String line
    • nextLine

      protected String nextLine
    • fileSize

      protected long fileSize
  • Constructor Details

    • FileIterator

      public FileIterator(BufferedReader reader)
    • FileIterator

      public FileIterator(String fileName)
  • Method Details

    • close

      public void close()
      Close file
    • countNewLineChars

      protected int countNewLineChars()
      Guess number of newline characters used (e.g. '\n' or '\r\n'
    • getFilePointer

      public long getFilePointer()
      Get position within file
    • getLine

      public String getLine()
    • getLineNum

      public int getLineNum()
    • guessNewLineChars

      protected void guessNewLineChars()
      Guess number of newline characters used (e.g. '\n' or '\r\n' Make sure we return to the current read position
    • hasNext

      public boolean hasNext()
      Specified by:
      hasNext in interface Iterator<T>
    • hasSeek

      public boolean hasSeek()
      Is 'seek' operation supported?
    • init

      protected void init(String fileName, int inOffset)
      Initialize
      Parameters:
      fileName - : Can be null (no file is opened)
    • isDebug

      public boolean isDebug()
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • load

      public List<T> load()
      Load all elements from a file into a list
    • next

      public T next()
      Specified by:
      next in interface Iterator<T>
    • readLine

      protected String readLine() throws IOException
      Read a line from reader
      Throws:
      IOException
    • readNext

      protected abstract T readNext()
      Read next element
    • ready

      protected boolean ready() throws IOException
      Is reader ready? I.e. Can we read a line?
      Throws:
      IOException
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<T>
    • seek

      public void seek(long pos) throws IOException
      Seek to 'pos' (jump to byte number 'pos' in the file
      Throws:
      IOException
    • setAutoClose

      public void setAutoClose(boolean autoClose)
    • setDebug

      public void setDebug(boolean debug)
    • setVerbose

      public void setVerbose(boolean verbose)
    • toString

      public String toString()
      Overrides:
      toString in class Object