diff --git a/core/src/main/java/org/bitcoinj/store/SPVBlockStore.java b/core/src/main/java/org/bitcoinj/store/SPVBlockStore.java index e1f7f9a82c4..988b1045a3a 100644 --- a/core/src/main/java/org/bitcoinj/store/SPVBlockStore.java +++ b/core/src/main/java/org/bitcoinj/store/SPVBlockStore.java @@ -162,6 +162,7 @@ else if (fileLength < randomAccessFile.length()) // Check or initialize the header bytes to ensure we don't try to open some random file. if (exists) { byte[] currentHeader = new byte[4]; + ((Buffer) buffer).rewind(); buffer.get(currentHeader); if (!Arrays.equals(currentHeader, MAGIC_HEADER)) throw new BlockStoreException("Magic header expected, got: " + ByteUtils.formatHex(currentHeader)); @@ -179,6 +180,7 @@ else if (fileLength < randomAccessFile.length()) } private void initNewStore(Block genesisBlock) throws Exception { + ((Buffer) buffer).rewind(); buffer.put(MAGIC_HEADER); // Insert the genesis block. lock.lock(); @@ -353,7 +355,6 @@ public void clear() throws Exception { buffer.put((byte)0); } // Initialize store again - ((Buffer) buffer).position(0); initNewStore(params.getGenesisBlock()); } finally { lock.unlock(); } }