From 281d9d5f4db7e50fcf171513b26115ff4a38567d Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Mon, 11 Apr 2011 17:38:37 +0000 Subject: [PATCH] HTTPCLIENT-1078: Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) do not close content stream in #writeTo() method git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1091140 13f79535-47bb-0310-9956-ffa450edef68 --- RELEASE_NOTES.txt | 4 ++++ .../http/client/entity/DecompressingEntity.java | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index c676427ee..daeab0112 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,5 +1,9 @@ Changes since 4.1.1 +* [HTTPCLIENT-1078] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) + do not close content stream in #writeTo() method. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1075] Decompressing entities (DeflateDecompressingEntity, GzipDecompressingEntity) do not correctly handle content streaming. Contributed by James Abley diff --git a/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java b/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java index 5e5b9e350..06272a6e7 100644 --- a/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java +++ b/httpclient/src/main/java/org/apache/http/client/entity/DecompressingEntity.java @@ -85,15 +85,17 @@ abstract class DecompressingEntity extends HttpEntityWrapper { if (outstream == null) { throw new IllegalArgumentException("Output stream may not be null"); } - InputStream instream = getContent(); + try { + byte[] buffer = new byte[BUFFER_SIZE]; - byte[] buffer = new byte[BUFFER_SIZE]; + int l; - int l; - - while ((l = instream.read(buffer)) != -1) { - outstream.write(buffer, 0, l); + while ((l = instream.read(buffer)) != -1) { + outstream.write(buffer, 0, l); + } + } finally { + instream.close(); } }