3
0
mirror of https://github.com/Qortal/altcoinj.git synced 2025-02-07 06:44:16 +00:00

Make a couple of inner classes static for efficiency, clears some FindBugs warnings.

Throw an exception if file delete in the block store failed, clears another warning.
This commit is contained in:
Mike Hearn 2011-08-05 20:46:23 +00:00
parent 48fce919aa
commit ddb1679a78
2 changed files with 8 additions and 4 deletions

View File

@ -258,7 +258,7 @@ public class Peer {
// A GetDataFuture wraps the result of a getBlock or (in future) getTransaction so the owner of the object can
// decide whether to wait forever, wait for a short while or check later after doing other work.
private class GetDataFuture<T extends Message> implements Future<T> {
private static class GetDataFuture<T extends Message> implements Future<T> {
private boolean cancelled;
private final InventoryItem item;
private final CountDownLatch latch;

View File

@ -73,7 +73,7 @@ public class BoundedOverheadBlockStore implements BlockStore {
private NetworkParameters params;
private FileChannel channel;
private class Record {
private static class Record {
// A BigInteger representing the total amount of work done so far on this chain. As of May 2011 it takes 8
// bytes to represent this field, so 16 bytes should be plenty for a long time.
private static final int CHAIN_WORK_BYTES = 16;
@ -154,7 +154,10 @@ public class BoundedOverheadBlockStore implements BlockStore {
// Create a new block store if the file wasn't found or anything went wrong whilst reading.
blockCache.clear();
try {
file.delete();
if (file.exists()) {
if (!file.delete())
throw new BlockStoreException("Could not delete old store in order to recreate it");
}
this.file = new RandomAccessFile(file, "rw"); // Create fresh.
this.channel = this.file.getChannel();
this.file.write(FILE_FORMAT_VERSION);
@ -191,7 +194,8 @@ public class BoundedOverheadBlockStore implements BlockStore {
}
// Chain head pointer is the first thing in the file.
byte[] chainHeadHash = new byte[32];
this.file.read(chainHeadHash);
if (this.file.read(chainHeadHash) < chainHeadHash.length)
throw new BlockStoreException("Truncated store: could not read chain head hash.");
this.chainHead = new Sha256Hash(chainHeadHash);
log.info("Read chain head from disk: {}", this.chainHead);
channel.position(channel.size() - Record.SIZE);