mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-01-18 21:32:35 +01:00
BlockFileLoader: fix end-of-file handling issue
When reads return fewer bytes than requested, it's either an end-of-file or an error. For now, we'll treat it as end-of-file.
This commit is contained in:
parent
2248513489
commit
c5cbff1e47
@ -165,10 +165,18 @@ public class BlockFileLoader implements Iterable<Block> {
|
||||
break;
|
||||
}
|
||||
byte[] sizeBytes = new byte[4];
|
||||
currentFileStream.read(sizeBytes, 0, 4);
|
||||
int sizeBytesRead = currentFileStream.read(sizeBytes, 0, 4);
|
||||
if (sizeBytesRead != 4) {
|
||||
nextBlock = null;
|
||||
return;
|
||||
}
|
||||
long size = ByteUtils.readUint32(sizeBytes, 0);
|
||||
byte[] dataBytes = new byte[(int) size];
|
||||
currentFileStream.read(dataBytes, 0, (int) size);
|
||||
int dataBytesRead = currentFileStream.read(dataBytes, 0, (int) size);
|
||||
if (dataBytesRead != size) {
|
||||
nextBlock = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
nextBlock = serializer.makeBlock(ByteBuffer.wrap(dataBytes));
|
||||
} catch (ProtocolException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user