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 boolean
autoClose
protected int
countNewLineChars
protected boolean
debug
protected java.lang.String
fileName
protected long
fileSize
protected java.lang.String
line
protected int
lineNum
protected T
next
protected java.lang.String
nextLine
protected java.io.BufferedReader
reader
protected boolean
verbose
-
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 void
close()
Close fileprotected int
countNewLineChars()
Guess number of newline characters used (e.g.long
getFilePointer()
Get position within filejava.lang.String
getLine()
int
getLineNum()
protected void
guessNewLineChars()
Guess number of newline characters used (e.g.boolean
hasNext()
boolean
hasSeek()
Is 'seek' operation supported?protected void
init(java.lang.String fileName, int inOffset)
Initializeboolean
isDebug()
java.util.Iterator<T>
iterator()
java.util.List<T>
load()
Load all elements from a file into a listT
next()
protected java.lang.String
readLine()
Read a line from readerprotected abstract T
readNext()
Read next elementprotected boolean
ready()
Is reader ready? I.e.void
remove()
void
seek(long pos)
Seek to 'pos' (jump to byte number 'pos' in the filevoid
setAutoClose(boolean autoClose)
void
setDebug(boolean debug)
void
setVerbose(boolean verbose)
java.lang.String
toString()
-
-
-
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:
hasNext
in 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:
iterator
in 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.IOException
Read a line from reader- Throws:
java.io.IOException
-
readNext
protected abstract T readNext()
Read next element
-
ready
protected boolean ready() throws java.io.IOException
Is reader ready? I.e. Can we read a line?- Throws:
java.io.IOException
-
remove
public void remove()
- Specified by:
remove
in interfacejava.util.Iterator<T>
-
seek
public void seek(long pos) throws java.io.IOException
Seek 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:
toString
in classjava.lang.Object
-
-