public void clear() throws Exception {
        lock.lock();
        try {
            // Clear caches
            blockCache.clear();
            notFoundCache.clear();
            // Clear file content
            ((Buffer) buffer).position(0);
            long fileLength = randomAccessFile.length();
            for (int i = 0; i < fileLength; i++) {
                buffer.put((byte)0);
            }
            // Initialize store again
            initNewStore(params.getGenesisBlock());
        } finally { lock.unlock(); }
    }
@Test
    public void clear() throws Exception {
        Context.propagate(new Context(100, Transaction.DEFAULT_TX_FEE, false, true));
        SPVBlockStore store = new SPVBlockStore(TESTNET, blockStoreFile);

        // Build a new block.
        Address to = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
        StoredBlock genesis = store.getChainHead();
        StoredBlock b1 = genesis.build(genesis.getHeader().createNextBlock(to).cloneAsHeader());
        store.put(b1);
        store.setChainHead(b1);
        assertEquals(b1.getHeader().getHash(), store.getChainHead().getHeader().getHash());
        store.clear();
        assertNull(store.get(b1.getHeader().getHash()));
        assertEquals(TESTNET.getGenesisBlock().getHash(), store.getChainHead().getHeader().getHash());
        store.close();
    }