RemoteFTempl: InputStream.close() in the finally

If exception happens in the `callback.doWithInputStream(inputStream)`,
we don't close the `inputStream = session.readRaw(remotePath)`.

* Move the `InputStream.close()` to the `finally` block of the
`SessionCallback` action in the `RemoteFileTemplate.get()`

**Cherry-pick to 5.0.x and 4.3.x**
This commit is contained in:
Artem Bilan
2018-10-05 12:02:21 -04:00
committed by Gary Russell
parent 1fe22ea35f
commit ef9c7609d5

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -399,11 +399,19 @@ public class RemoteFileTemplate<F> implements RemoteFileOperations<F>, Initializ
@Override
public Boolean doInSession(Session<F> session) throws IOException {
InputStream inputStream = session.readRaw(remotePath);
callback.doWithInputStream(inputStream);
inputStream.close();
return session.finalizeRaw();
InputStream inputStream = null;
try {
inputStream = session.readRaw(remotePath);
callback.doWithInputStream(inputStream);
return session.finalizeRaw();
}
finally {
if (inputStream != null) {
inputStream.close();
}
}
}
});
}