CODENVY-26: Fix stream closing before it is direct use

6.19.x
Anton Korneta 2016-03-11 10:18:19 +02:00
parent cb46caa3ba
commit 116cb33f3b
1 changed files with 10 additions and 5 deletions

View File

@ -659,17 +659,22 @@ public class DockerConnector {
* @apiNote this method implements 1.20 docker API and requires docker not less than 1.8.0 version
*/
public InputStream getResource(String container, String sourcePath) throws IOException {
try (DockerConnection connection = connectionFactory.openConnection(dockerDaemonUri)
.method("GET")
.path("/containers/" + container + "/archive")
.query("path", sourcePath)) {
DockerConnection connection = null;
try {
connection = connectionFactory.openConnection(dockerDaemonUri)
.method("GET")
.path("/containers/" + container + "/archive")
.query("path", sourcePath);
final DockerResponse response = connection.request();
final int status = response.getStatus();
if (status != OK.getStatusCode()) {
throw getDockerException(response);
}
return new CloseConnectionInputStream(response.getInputStream(), connection);
} catch (IOException io) {
connection.close();
throw io;
}
}