    private void load(File file) throws IOException, BlockStoreException {
        LOG("Reading block store from " + file.getAbsolutePath());
        FileInputStream input = new FileInputStream(file);
        int version = input.read();
        if (version == -1) {
            throw new FileNotFoundException(file.getName() + " does not exist or is empty");
        }
        if (version != 1) {
            throw new BlockStoreException("Bad version number: " + version);
        }
        byte[] chainHeadHash = new byte[32];
        input.read(chainHeadHash);
        this.chainHead = new Sha256Hash(chainHeadHash);
        LOG("Read chain head from disk: " + this.chainHead);
        long now = System.currentTimeMillis();
        byte[] headerBytes = new byte[Block.HEADER_SIZE];
        try {
            while (true) {
                if (input.read(headerBytes) < 80) {
                    break;
                }
                Block b = new Block(params, headerBytes);
                StoredBlock prev = get(b.getPrevBlockHash());
                StoredBlock s;
                if (prev == null) {
                    if (b.equals(params.genesisBlock)) {
                        s = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0);
                    } else {
                        throw new BlockStoreException("Could not connect " + Utils.bytesToHexString(b.getHash()) + " to "
                            + Utils.bytesToHexString(b.getPrevBlockHash()));
                    }
                } else {
                    b.verify();
                    s = prev.build(b);
                }
                blockMap.put(new Sha256Hash(b.getHash()), s);
            }
        } catch (ProtocolException e) {
            throw new BlockStoreException(e);
        } catch (VerificationException e) {
            throw new BlockStoreException(e);
        }
        long elapsed = System.currentTimeMillis() - now;
        LOG("Block chain read complete in " + elapsed + "ms");
    }

    private void load(File file) throws IOException, BlockStoreException {
        LOG("Reading block store from " + file.getAbsolutePath());
        InputStream input = new BufferedInputStream(new FileInputStream(file));
        int version = input.read();
        if (version == -1) {
            throw new FileNotFoundException(file.getName() + " does not exist or is empty");
        }
        if (version != 1) {
            throw new BlockStoreException("Bad version number: " + version);
        }
        byte[] chainHeadHash = new byte[32];
        input.read(chainHeadHash);
        this.chainHead = new Sha256Hash(chainHeadHash);
        LOG("Read chain head from disk: " + this.chainHead);
        long now = System.currentTimeMillis();
        byte[] headerBytes = new byte[Block.HEADER_SIZE];
        try {
            while (true) {
                if (input.read(headerBytes) < 80) {
                    break;
                }
                Block b = new Block(params, headerBytes);
                StoredBlock prev = get(b.getPrevBlockHash());
                StoredBlock s;
                if (prev == null) {
                    if (b.equals(params.genesisBlock)) {
                        s = new StoredBlock(params.genesisBlock.cloneAsHeader(), params.genesisBlock.getWork(), 0);
                    } else {
                        throw new BlockStoreException("Could not connect " + Utils.bytesToHexString(b.getHash()) + " to "
                            + Utils.bytesToHexString(b.getPrevBlockHash()));
                    }
                } else {
                    b.verify();
                    s = prev.build(b);
                }
                blockMap.put(new Sha256Hash(b.getHash()), s);
            }
        } catch (ProtocolException e) {
            throw new BlockStoreException(e);
        } catch (VerificationException e) {
            throw new BlockStoreException(e);
        }
        long elapsed = System.currentTimeMillis() - now;
        LOG("Block chain read complete in " + elapsed + "ms");
    }
