From 12a652bd1e73a85d3d7e6ba48d29deb3fa470476 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Fri, 4 Jan 2013 17:38:05 +0100 Subject: [PATCH] Close the temporary FileInputStream created in Sha256Hash.hashFileContents. Updates issue 265. --- .../src/main/java/com/google/bitcoin/core/Sha256Hash.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java b/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java index 6a57d368..6b8a7c60 100644 --- a/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java +++ b/core/src/main/java/com/google/bitcoin/core/Sha256Hash.java @@ -73,8 +73,12 @@ public class Sha256Hash implements Serializable { * @throws IOException */ public static Sha256Hash hashFileContents(File f) throws IOException { - // Lame implementation that just reads the entire file into RAM. Can be made more efficient later. - return create(ByteStreams.toByteArray(new FileInputStream(f))); + FileInputStream in = new FileInputStream(f); + try { + return create(ByteStreams.toByteArray(in)); + } finally { + in.close(); + } } /**