[
https://issues.apache.org/jira/browse/CXF-7585?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16283856#comment-16283856
]
ASF GitHub Bot commented on CXF-7585:
-------------------------------------
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:
[email protected]
> base64 attachment encoding does not close the InputSteam
> --------------------------------------------------------
>
> Key: CXF-7585
> URL: https://issues.apache.org/jira/browse/CXF-7585
> Project: CXF
> Issue Type: Bug
> Components: Core
> Affects Versions: 3.1.14, 3.2.1
> Reporter: Joern Gebhardt
>
> The {{AttachmentSerializer}} class gets in the {{writeAttachments()}} and
> {{InputStream}} from the {{DataHandler}} and calls the {{encodeBase64(..)}}
> method.
> However, it does not close the InputStream.
> Instead a try-with-resource approach should be used here
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)