Package org.bitcoinj.utils
Class BlockFileLoader
- java.lang.Object
-
- org.bitcoinj.utils.BlockFileLoader
-
- All Implemented Interfaces:
java.lang.Iterable<Block>
public class BlockFileLoader extends java.lang.Object implements java.lang.Iterable<Block>
This class reads block files stored in the Bitcoin Core format. This is simply a way to concatenate blocks together. Importing block data with this tool can be a lot faster than syncing over the network, if you have the files available.
In order to comply with
Iterable
,BlockFileLoader.BlockFileIterator
swallows a lot ofIOException
s, which may result in a few blocks being missed followed by a huge set of orphan blocks.To blindly import all files which can be found in Bitcoin Core (version 0.8 or higher) datadir automatically, try this code fragment:
BlockFileLoader loader = new BlockFileLoader(BlockFileLoader.getReferenceClientBlockFileList()); for (Block block : loader) { try { chain.add(block); } catch (Exception e) { } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
BlockFileLoader.BlockFileIterator
Iterates all the blocks in a single block file.
-
Constructor Summary
Constructors Constructor Description BlockFileLoader(Network network, java.io.File blocksDir)
BlockFileLoader(Network network, java.util.List<java.io.File> files)
BlockFileLoader(NetworkParameters params, java.io.File blocksDir)
Deprecated.BlockFileLoader(NetworkParameters params, java.util.List<java.io.File> files)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.io.File
defaultBlocksDir()
protected java.util.Spliterator<java.nio.ByteBuffer>
fileBlockSpliterator(java.io.File file)
protected java.util.stream.Stream<java.nio.ByteBuffer>
fileBlockStream(java.io.File file)
static java.util.List<java.io.File>
getReferenceClientBlockFileList()
static java.util.List<java.io.File>
getReferenceClientBlockFileList(java.io.File blocksDir)
Gets the list of files which contain blocks from Bitcoin Core.java.util.Iterator<Block>
iterator()
java.util.stream.Stream<Block>
stream()
java.util.stream.Stream<java.nio.ByteBuffer>
streamBuffers()
-
-
-
Constructor Detail
-
BlockFileLoader
public BlockFileLoader(Network network, java.io.File blocksDir)
-
BlockFileLoader
public BlockFileLoader(Network network, java.util.List<java.io.File> files)
-
BlockFileLoader
@Deprecated public BlockFileLoader(NetworkParameters params, java.io.File blocksDir)
Deprecated.
-
BlockFileLoader
@Deprecated public BlockFileLoader(NetworkParameters params, java.util.List<java.io.File> files)
Deprecated.
-
-
Method Detail
-
getReferenceClientBlockFileList
public static java.util.List<java.io.File> getReferenceClientBlockFileList(java.io.File blocksDir)
Gets the list of files which contain blocks from Bitcoin Core.
-
getReferenceClientBlockFileList
public static java.util.List<java.io.File> getReferenceClientBlockFileList()
-
defaultBlocksDir
public static java.io.File defaultBlocksDir()
-
iterator
public java.util.Iterator<Block> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<Block>
-
stream
public java.util.stream.Stream<Block> stream()
-
streamBuffers
public java.util.stream.Stream<java.nio.ByteBuffer> streamBuffers()
-
fileBlockStream
protected java.util.stream.Stream<java.nio.ByteBuffer> fileBlockStream(java.io.File file)
-
fileBlockSpliterator
protected java.util.Spliterator<java.nio.ByteBuffer> fileBlockSpliterator(java.io.File file)
-
-