You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2017/12/08 17:10:22 UTC

[GitHub] dkulp closed pull request #355: [CXF-7585] Close InputStream in AttachmentSerializer when base64 encoding is used

dkulp closed pull request #355: [CXF-7585] Close InputStream in AttachmentSerializer when base64 encoding is used
URL: https://github.com/apache/cxf/pull/355
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
index 9a4cb0e00a4..82c88318571 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
@@ -278,7 +278,9 @@ public void writeAttachments() throws IOException {
                              headers, writer);
                 out.write(writer.getBuffer().toString().getBytes(encoding));
                 if ("base64".equals(contentTransferEncoding)) {
-                    encodeBase64(handler.getInputStream(), out, IOUtils.DEFAULT_BUFFER_SIZE);
+                    try (InputStream inputStream = handler.getInputStream()) {
+                        encodeBase64(inputStream, out, IOUtils.DEFAULT_BUFFER_SIZE);
+                    }
                 } else {
                     handler.writeTo(out);
                 }
@@ -308,7 +310,7 @@ private int encodeBase64(InputStream input, OutputStream output, int bufferSize)
             if (n == 0) {
                 throw new IOException("0 bytes read in violation of InputStream.read(byte[])");
             }
-            Base64Utility.encodeAndStream(buffer, 0, n, out);
+            Base64Utility.encodeAndStream(buffer, 0, n, output);
             total += n;
             n = input.read(buffer);
         }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services