From 74152c6e70cab59b8e59ca04b4bcccf549822b61 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Mon, 30 May 2011 15:52:37 +0000 Subject: [PATCH] Add FileInputStream/FileOutputStream accepting versions of the wallet load/save methods. This makes things a bit easier on Android. --- src/com/google/bitcoin/core/Wallet.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/google/bitcoin/core/Wallet.java b/src/com/google/bitcoin/core/Wallet.java index 88906ee8..05c90807 100644 --- a/src/com/google/bitcoin/core/Wallet.java +++ b/src/com/google/bitcoin/core/Wallet.java @@ -149,18 +149,33 @@ public class Wallet implements Serializable { * Uses Java serialization to save the wallet to the given file. */ 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.close(); } + /** * Returns a wallet deserialized from the given file. */ 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; try { - ois = new ObjectInputStream(new FileInputStream(f)); + ois = new ObjectInputStream(f); return (Wallet) ois.readObject(); } catch (ClassNotFoundException e) { throw new RuntimeException(e);