mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-12 10:31:06 +01:00
Tighten scope of the FileInputStream in WalletAppKit to avoid lock collisions on Windows. Resolves issue 556.
This commit is contained in:
parent
408bca3433
commit
acebe8e3d2
1 changed files with 10 additions and 9 deletions
|
@ -189,7 +189,6 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
throw new IOException("Could not create named directory.");
|
throw new IOException("Could not create named directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileInputStream walletStream = null;
|
|
||||||
try {
|
try {
|
||||||
File chainFile = new File(directory, filePrefix + ".spvchain");
|
File chainFile = new File(directory, filePrefix + ".spvchain");
|
||||||
boolean chainFileExists = chainFile.exists();
|
boolean chainFileExists = chainFile.exists();
|
||||||
|
@ -216,12 +215,16 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
if (this.userAgent != null)
|
if (this.userAgent != null)
|
||||||
vPeerGroup.setUserAgent(userAgent, version);
|
vPeerGroup.setUserAgent(userAgent, version);
|
||||||
if (vWalletFile.exists()) {
|
if (vWalletFile.exists()) {
|
||||||
walletStream = new FileInputStream(vWalletFile);
|
FileInputStream walletStream = new FileInputStream(vWalletFile);
|
||||||
|
try {
|
||||||
vWallet = new Wallet(params);
|
vWallet = new Wallet(params);
|
||||||
addWalletExtensions(); // All extensions must be present before we deserialize
|
addWalletExtensions(); // All extensions must be present before we deserialize
|
||||||
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
|
new WalletProtobufSerializer().readWallet(WalletProtobufSerializer.parseToProto(walletStream), vWallet);
|
||||||
if (shouldReplayWallet)
|
if (shouldReplayWallet)
|
||||||
vWallet.clearTransactions(0);
|
vWallet.clearTransactions(0);
|
||||||
|
} finally {
|
||||||
|
walletStream.close();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
vWallet = new Wallet(params);
|
vWallet = new Wallet(params);
|
||||||
vWallet.addKey(new ECKey());
|
vWallet.addKey(new ECKey());
|
||||||
|
@ -270,8 +273,6 @@ public class WalletAppKit extends AbstractIdleService {
|
||||||
}
|
}
|
||||||
} catch (BlockStoreException e) {
|
} catch (BlockStoreException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
} finally {
|
|
||||||
if (walletStream != null) walletStream.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue