Package org.snpeff.fileIterator
Class FileIterator<T>
- java.lang.Object
-
- org.snpeff.fileIterator.FileIterator<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Iterator<T>
- Direct Known Subclasses:
FastaFileIterator,LineClassFileIterator,LineFileIterator,MarkerFileIterator,PedFileIterator,SamFileIterator
public abstract class FileIterator<T> extends java.lang.Object implements java.lang.Iterable<T>, java.util.Iterator<T>Opens a file and iterates over all objectsin the file Note: The file is not loaded in memory, thus allows to iterate over very large files - Author:
- pcingola
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanautoCloseprotected intcountNewLineCharsprotected booleandebugprotected java.lang.StringfileNameprotected longfileSizeprotected java.lang.Stringlineprotected intlineNumprotected Tnextprotected java.lang.StringnextLineprotected java.io.BufferedReaderreaderprotected booleanverbose
-
Constructor Summary
Constructors Constructor Description FileIterator(java.io.BufferedReader reader)FileIterator(java.lang.String fileName)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Close fileprotected intcountNewLineChars()Guess number of newline characters used (e.g.longgetFilePointer()Get position within filejava.lang.StringgetLine()intgetLineNum()protected voidguessNewLineChars()Guess number of newline characters used (e.g.booleanhasNext()booleanhasSeek()Is 'seek' operation supported?protected voidinit(java.lang.String fileName, int inOffset)InitializebooleanisDebug()java.util.Iterator<T>iterator()java.util.List<T>load()Load all elements from a file into a listTnext()protected java.lang.StringreadLine()Read a line from readerprotected abstract TreadNext()Read next elementprotected booleanready()Is reader ready? I.e.voidremove()voidseek(long pos)Seek to 'pos' (jump to byte number 'pos' in the filevoidsetAutoClose(boolean autoClose)voidsetDebug(boolean debug)voidsetVerbose(boolean verbose)java.lang.StringtoString()
-
-
-
Field Detail
-
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 java.io.BufferedReader reader
-
fileName
protected java.lang.String fileName
-
line
protected java.lang.String line
-
nextLine
protected java.lang.String nextLine
-
fileSize
protected long fileSize
-
-
Method Detail
-
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 java.lang.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:
hasNextin interfacejava.util.Iterator<T>
-
hasSeek
public boolean hasSeek()
Is 'seek' operation supported?
-
init
protected void init(java.lang.String fileName, int inOffset)Initialize- Parameters:
fileName- : Can be null (no file is opened)
-
isDebug
public boolean isDebug()
-
iterator
public java.util.Iterator<T> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
load
public java.util.List<T> load()
Load all elements from a file into a list
-
readLine
protected java.lang.String readLine() throws java.io.IOExceptionRead a line from reader- Throws:
java.io.IOException
-
readNext
protected abstract T readNext()
Read next element
-
ready
protected boolean ready() throws java.io.IOExceptionIs reader ready? I.e. Can we read a line?- Throws:
java.io.IOException
-
remove
public void remove()
- Specified by:
removein interfacejava.util.Iterator<T>
-
seek
public void seek(long pos) throws java.io.IOExceptionSeek to 'pos' (jump to byte number 'pos' in the file- Throws:
java.io.IOException
-
setAutoClose
public void setAutoClose(boolean autoClose)
-
setDebug
public void setDebug(boolean debug)
-
setVerbose
public void setVerbose(boolean verbose)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-