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.
This commit is contained in:
Andrew Gaul 2014-02-18 09:12:05 -08:00
parent a656c7292f
commit 1f08b692cd
1 changed files with 6 additions and 1 deletions

View File

@ -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