From 9dae3a692ef01e2c42200ef055d2340754f7140d Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 18 Feb 2014 09:12:05 -0800 Subject: [PATCH] JCLOUDS-473: Close FileInputStream in Wire.copy FileBackedOutputStream.asByteSource.getInput returns a FileInputStream which we do not close. We later call FileBackedOutputStream.reset which removes the underlying File. This fails on Windows which does not support deleting an open file and leaks resources on other platforms. Eagerly close to address this issue. --- core/src/main/java/org/jclouds/logging/internal/Wire.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/logging/internal/Wire.java b/core/src/main/java/org/jclouds/logging/internal/Wire.java index 160945005d..fbc0b84b0b 100644 --- a/core/src/main/java/org/jclouds/logging/internal/Wire.java +++ b/core/src/main/java/org/jclouds/logging/internal/Wire.java @@ -93,7 +93,12 @@ public abstract class Wire { long bytesRead = ByteStreams.copy(instream, out); if (bytesRead >= limit) logger.debug("over limit %d/%d: wrote temp file", bytesRead, limit); - wire(header, out.asByteSource().getInput()); + InputStream is = out.asByteSource().openStream(); + try { + wire(header, is); + } finally { + is.close(); + } // we must call FileBackedOutputStream.reset to remove temporary file return new FilterInputStream(out.asByteSource().getInput()) { @Override