mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-22 14:22:45 +01:00
BlockFileLoader: buffer reading of block files
For now, use 16MB of buffer. That's enough to hold 16 "full" 1MB blocks.
This commit is contained in:
parent
c5cbff1e47
commit
47129b91e5
1 changed files with 5 additions and 2 deletions
|
@ -23,6 +23,7 @@ import org.bitcoinj.core.MessageSerializer;
|
|||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.bitcoinj.core.ProtocolException;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -58,6 +59,8 @@ import static org.bitcoinj.base.internal.Preconditions.checkArgument;
|
|||
* }</p>
|
||||
*/
|
||||
public class BlockFileLoader implements Iterable<Block> {
|
||||
private static final int BLOCKFILE_BUFFER_SIZE = 16 * 1024 * 1024;
|
||||
|
||||
/**
|
||||
* Gets the list of files which contain blocks from Bitcoin Core.
|
||||
*/
|
||||
|
@ -118,12 +121,12 @@ public class BlockFileLoader implements Iterable<Block> {
|
|||
*/
|
||||
public class BlockFileIterator implements Iterator<Block> {
|
||||
private final File file;
|
||||
private final FileInputStream currentFileStream;
|
||||
private final BufferedInputStream currentFileStream;
|
||||
private org.bitcoinj.core.Block nextBlock = null;
|
||||
|
||||
public BlockFileIterator(File blockFile) throws FileNotFoundException {
|
||||
this.file = blockFile;
|
||||
currentFileStream = new FileInputStream(blockFile);
|
||||
currentFileStream = new BufferedInputStream(new FileInputStream(blockFile), BLOCKFILE_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue