# Class FileTxnLog.FileTxnIterator

java.lang.Object
org.apache.zookeeper.server.persistence.FileTxnLog.FileTxnIterator

All Implemented Interfaces:
  `Closeable, AutoCloseable, TxnLog.TxnIterator`

Enclosing class:
  `FileTxnLog`

public static class FileTxnLog.FileTxnIterator extends Object implements TxnLog.TxnIterator
this class implements the txnlog iterator interface which is used for reading the transaction logs

## Constructor Summary

Constructors
Constructor
Description
`FileTxnIterator(File logDir, long zxid)`
create an iterator over a transaction database directory
`FileTxnIterator(File logDir, long zxid, boolean fastForward)`
create an iterator over a transaction database directory

## Method Summary

Modifier and Type
Method
Description
`void`
`close()`
close the iterator and release the resources.
`protected InputArchive`
`createInputArchive(File logFile)`
Invoked to indicate that the input stream has been created.
`TxnDigest`
`getDigest()`
`TxnHeader`
`getHeader()`
return the current header
`long`
`getStorageSize()`
Return total storage size of txnlog that will return by this iterator.
`Record`
`getTxn()`
return the current transaction
`protected void`
`inStreamCreated(InputArchive ia, InputStream is)`
read the header from the inputarchive
`protected Checksum`
`makeChecksumAlgorithm()`
create a checksum algorithm
`boolean`
`next()`
the iterator that moves to the next transaction

### Methods inherited from class Object

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

## Constructor Details

### FileTxnIterator

public FileTxnIterator(File logDir, long zxid, boolean fastForward) throws IOException
create an iterator over a transaction database directory

Parameters:
  `logDir` - the transaction database directory
  `zxid` - the zxid to start reading from
  `fastForward` - true if the iterator should be fast forwarded to point to the txn of a given zxid, else the iterator will point to the starting txn of a txnlog that may contain txn of a given zxid
Throws:
  `IOException`

### FileTxnIterator

public FileTxnIterator(File logDir, long zxid) throws IOException
create an iterator over a transaction database directory

Parameters:
  `logDir` - the transaction database directory
  `zxid` - the zxid to start reading from
Throws:
  `IOException`

## Method Details

### getStorageSize

public long getStorageSize()
Return total storage size of txnlog that will return by this iterator.

Specified by:
  `getStorageSize` in interface `TxnLog.TxnIterator`

### inStreamCreated

protected void inStreamCreated(InputArchive ia, InputStream is) throws IOException
read the header from the inputarchive

Parameters:
  `ia` - the inputarchive to be read from
  `is` - the inputstream
Throws:
  `IOException`

### createInputArchive

protected InputArchive createInputArchive(File logFile) throws IOException
Invoked to indicate that the input stream has been created.

Parameters:
  `logFile` - the file to read.
Throws:
  `IOException`

### makeChecksumAlgorithm

protected Checksum makeChecksumAlgorithm()
create a checksum algorithm

Returns:
  the checksum algorithm

### next

public boolean next() throws IOException
the iterator that moves to the next transaction

Specified by:
  `next` in interface `TxnLog.TxnIterator`
Returns:
  true if there is more transactions to be read false if not.
Throws:
  `IOException`

### getHeader

public TxnHeader getHeader()
return the current header

Specified by:
  `getHeader` in interface `TxnLog.TxnIterator`
Returns:
  the current header that is read

### getTxn

public Record getTxn()
return the current transaction

Specified by:
  `getTxn` in interface `TxnLog.TxnIterator`
Returns:
  the current transaction that is read

### getDigest

public TxnDigest getDigest()

Specified by:
  `getDigest` in interface `TxnLog.TxnIterator`
Returns:
  the digest associated with the transaction.

### close

public void close() throws IOException
close the iterator and release the resources.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Specified by:
  `close` in interface `TxnLog.TxnIterator`
Throws:
  `IOException`