You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2020/01/10 16:15:55 UTC
[cxf] 03/03: Optimize a bit, close the dangling input stream
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 02a2df2dca1d5c19d682beb33d90d01cbb036433
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Fri Jan 10 11:10:49 2020 -0500
Optimize a bit, close the dangling input stream
(cherry picked from commit 42ae16e8fafcb172e28c481e3052a40e5e5108fb)
---
.../main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 9eeb4ab..61ec6e4 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -19,8 +19,6 @@
package org.apache.cxf.jaxrs.utils;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -92,6 +90,7 @@ import org.apache.cxf.common.util.ReflectionUtil;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.ReaderInputStream;
@@ -1893,14 +1892,13 @@ public final class JAXRSUtils {
// copy the input stream so that it is not inadvertently closed
private static InputStream copyAndGetEntityStream(Message m) {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- IOUtils.copy(m.getContent(InputStream.class), baos);
+ LoadingByteArrayOutputStream baos = new LoadingByteArrayOutputStream();
+ try (InputStream in = m.getContent(InputStream.class)) {
+ IOUtils.copy(in, baos);
} catch (IOException e) {
throw ExceptionUtils.toInternalServerErrorException(e, null);
}
- final byte[] copiedBytes = baos.toByteArray();
- m.setContent(InputStream.class, new ByteArrayInputStream(copiedBytes));
- return new ByteArrayInputStream(copiedBytes);
+ m.setContent(InputStream.class, baos.createInputStream());
+ return baos.createInputStream();
}
}