# 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 <T> in 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 String`
`fileName`
`protected long`
`fileSize`
`protected String`
`line`
`protected int`
`lineNum`
`protected T`
`next`
`protected String`
`nextLine`
`protected BufferedReader`
`reader`
`protected boolean`
`verbose`

## Constructor Summary

Constructors
Constructor
Description
`FileIterator(BufferedReader reader)`
`FileIterator(String fileName)`

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
Close file
`protected int`
`countNewLineChars()`
Guess number of newline characters used (e.g.
`long`
`getFilePointer()`
Get position within file
`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(String fileName, int inOffset)`
Initialize
`boolean`
`isDebug()`
`Iterator<T>`
`iterator()`
`List<T>`
`load()`
Load all elements from a file into a list
`T`
`next()`
`protected String`
`readLine()`
Read a line from reader
`protected abstract T`
`readNext()`
Read next element
`protected boolean`
`ready()`
Is reader ready? I.e.
`void`
`remove()`
`void`
`seek(long pos)`
Seek to 'pos' (jump to byte number 'pos' in the file
`void`
`setAutoClose(boolean autoClose)`
`void`
`setDebug(boolean debug)`
`void`
`setVerbose(boolean verbose)`
`String`
`toString()`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface Iterable

`forEach, spliterator`

### Methods inherited from interface Iterator

`forEachRemaining`

## 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`