mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-03-04 09:59:34 +01:00
Add FileInputStream/FileOutputStream accepting versions of the wallet load/save methods. This makes things a bit easier on Android.
This commit is contained in:
parent
06c84c2c23
commit
74152c6e70
1 changed files with 17 additions and 2 deletions
|
@ -149,18 +149,33 @@ public class Wallet implements Serializable {
|
||||||
* Uses Java serialization to save the wallet to the given file.
|
* Uses Java serialization to save the wallet to the given file.
|
||||||
*/
|
*/
|
||||||
public synchronized void saveToFile(File f) throws IOException {
|
public synchronized void saveToFile(File f) throws IOException {
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
|
saveToFileStream(new FileOutputStream(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uses Java serialization to save the wallet to the given file stream.
|
||||||
|
*/
|
||||||
|
public synchronized void saveToFileStream(FileOutputStream f) throws IOException {
|
||||||
|
ObjectOutputStream oos = new ObjectOutputStream(f);
|
||||||
oos.writeObject(this);
|
oos.writeObject(this);
|
||||||
oos.close();
|
oos.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a wallet deserialized from the given file.
|
* Returns a wallet deserialized from the given file.
|
||||||
*/
|
*/
|
||||||
public static Wallet loadFromFile(File f) throws IOException {
|
public static Wallet loadFromFile(File f) throws IOException {
|
||||||
|
return loadFromFileStream(new FileInputStream(f));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a wallet deserialied from the given file input stream.
|
||||||
|
*/
|
||||||
|
public static Wallet loadFromFileStream(FileInputStream f) throws IOException {
|
||||||
ObjectInputStream ois = null;
|
ObjectInputStream ois = null;
|
||||||
try {
|
try {
|
||||||
ois = new ObjectInputStream(new FileInputStream(f));
|
ois = new ObjectInputStream(f);
|
||||||
return (Wallet) ois.readObject();
|
return (Wallet) ois.readObject();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue