Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 24B7719DD2 for ; Mon, 25 Apr 2016 15:14:49 +0000 (UTC) Received: (qmail 54522 invoked by uid 500); 25 Apr 2016 15:14:49 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 54388 invoked by uid 500); 25 Apr 2016 15:14:48 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 54368 invoked by uid 99); 25 Apr 2016 15:14:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Apr 2016 15:14:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9B8E8DFDE3; Mon, 25 Apr 2016 15:14:48 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: coheigea@apache.org To: commits@cxf.apache.org Date: Mon, 25 Apr 2016 15:14:48 -0000 Message-Id: <8cc32b2e3e7f432e9df371f857f58bb7@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] cxf git commit: More stream stuff Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 563ad5b39 -> c8636c036 More stream stuff Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/71811014 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/71811014 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/71811014 Branch: refs/heads/3.1.x-fixes Commit: 71811014ff69c2d7a9d7b884a6eb360723b189d8 Parents: 563ad5b Author: Colm O hEigeartaigh Authored: Mon Apr 25 14:48:17 2016 +0100 Committer: Colm O hEigeartaigh Committed: Mon Apr 25 14:48:17 2016 +0100 ---------------------------------------------------------------------- .../cxf/databinding/source/NodeDataReader.java | 5 ++-- .../handler/logical/LogicalMessageImpl.java | 8 ++--- .../apache/cxf/javascript/fortest/MtoMImpl.java | 3 +- .../netty/server/NettyHttpServerEngineTest.java | 7 +++-- .../MultiplexHttpAddressClientServerTest.java | 14 ++++----- .../apache/cxf/systest/mtom/MtomPolicyTest.java | 8 ++--- .../apache/cxf/systest/mtom/MtomServerTest.java | 31 ++++++++++---------- 7 files changed, 36 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java b/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java index aaf36ce..bd5969d 100644 --- a/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java +++ b/core/src/main/java/org/apache/cxf/databinding/source/NodeDataReader.java @@ -55,12 +55,11 @@ public class NodeDataReader implements DataReader { XMLStreamReader reader = StaxUtils.createXMLStreamReader((Element)input); return new StaxSource(reader); } else if (StreamSource.class.isAssignableFrom(type)) { - try { - CachedOutputStream out = new CachedOutputStream(); + try (CachedOutputStream out = new CachedOutputStream()) { StaxUtils.writeTo(input, out); InputStream is = out.getInputStream(); out.close(); - + return new StreamSource(is); } catch (IOException e) { throw new Fault("COULD_NOT_READ_XML_STREAM", LOG, e); http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java index 835289a..d0c7b1e 100644 --- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java +++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/handler/logical/LogicalMessageImpl.java @@ -144,13 +144,11 @@ public class LogicalMessageImpl implements LogicalMessage { if (message instanceof SoapMessage) { // StreamSource may only be used once, need to make a copy if (obj instanceof StreamSource) { - try { - CachedOutputStream cos = new CachedOutputStream(); + try (CachedOutputStream cos = new CachedOutputStream()) { StaxUtils.copy(obj, cos); obj = new StreamSource(cos.getInputStream()); message.setContent(Source.class, new StreamSource(cos.getInputStream())); - cos.close(); } catch (Exception e) { throw new Fault(e); } @@ -159,14 +157,12 @@ public class LogicalMessageImpl implements LogicalMessage { if (mode == Service.Mode.PAYLOAD) { source = obj; } else { - try { - CachedOutputStream cos = new CachedOutputStream(); + try (CachedOutputStream cos = new CachedOutputStream()) { StaxUtils.copy(obj, cos); InputStream in = cos.getInputStream(); SOAPMessage msg = initSOAPMessage(in); source = new DOMSource(SAAJUtils.getBody(msg).getFirstChild()); in.close(); - cos.close(); } catch (Exception e) { throw new Fault(e); } http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/fortest/MtoMImpl.java ---------------------------------------------------------------------- diff --git a/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/fortest/MtoMImpl.java b/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/fortest/MtoMImpl.java index cbd1429..4149ff6 100644 --- a/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/fortest/MtoMImpl.java +++ b/rt/javascript/javascript-tests/src/test/java/org/apache/cxf/javascript/fortest/MtoMImpl.java @@ -46,8 +46,7 @@ public class MtoMImpl implements MtoM { public MtoMImpl() { InputStream someData = getClass().getClassLoader().getResourceAsStream("org/apache/cxf/javascript/cxf-utils.js"); - StringWriter sw = new StringWriter(); - try { + try (StringWriter sw = new StringWriter()) { InputStreamReader isr = new InputStreamReader(someData, "utf-8"); IOUtils.copy(isr, sw, 4096); returnData = sw.toString(); http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineTest.java ---------------------------------------------------------------------- diff --git a/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineTest.java b/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineTest.java index 1c82680..f03466d 100644 --- a/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineTest.java +++ b/rt/transports/http-netty/netty-server/src/test/java/org/apache/cxf/transport/http/netty/server/NettyHttpServerEngineTest.java @@ -148,8 +148,9 @@ public class NettyHttpServerEngineTest extends Assert { assertTrue(connection instanceof HttpURLConnection); connection.connect(); InputStream in = connection.getInputStream(); - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - IOUtils.copy(in, buffer); - return buffer.toString(); + try (ByteArrayOutputStream buffer = new ByteArrayOutputStream()) { + IOUtils.copy(in, buffer); + return buffer.toString(); + } } } http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java index d358eb0..62b1e0a 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/factory_pattern/MultiplexHttpAddressClientServerTest.java @@ -167,13 +167,13 @@ public class MultiplexHttpAddressClientServerTest extends AbstractBusClientServe URL url = new URL(address + "?wsdl"); URLConnection urlConn = url.openConnection(); - BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); - - while (br.ready()) { - String str = br.readLine(); - if (str.contains("soap:address") - && str.contains("location=" + "\"" + address + "\"")) { - return true; + try (BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()))) { + while (br.ready()) { + String str = br.readLine(); + if (str.contains("soap:address") + && str.contains("location=" + "\"" + address + "\"")) { + return true; + } } } return false; http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java index 3d44399..3963b93 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java @@ -164,10 +164,10 @@ public class MtomPolicyTest extends AbstractBusClientServerTestBase { assertEquals(1, attachments.size()); Attachment inAtt = attachments.iterator().next(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); - out.close(); - assertEquals(27364, out.size()); + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); + assertEquals(27364, out.size()); + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/71811014/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java ---------------------------------------------------------------------- diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java index 4285378..22d0f86 100644 --- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java +++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/mtom/MtomServerTest.java @@ -122,10 +122,10 @@ public class MtomServerTest extends AbstractBusClientServerTestBase { assertEquals(1, attachments.size()); Attachment inAtt = attachments.iterator().next(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); - out.close(); - assertEquals(27364, out.size()); + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); + assertEquals(27364, out.size()); + } } @Test @@ -168,12 +168,13 @@ public class MtomServerTest extends AbstractBusClientServerTestBase { if (is == null) { throw new RuntimeException("Could not find resource " + "request"); } - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - IOUtils.copy(is, bout); - String s = bout.toString(StandardCharsets.UTF_8.name()); - s = s.replaceAll(":9036/", ":" + PORT2 + "/"); + try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) { + IOUtils.copy(is, bout); + String s = bout.toString(StandardCharsets.UTF_8.name()); + s = s.replaceAll(":9036/", ":" + PORT2 + "/"); - os.write(s.getBytes(StandardCharsets.UTF_8)); + os.write(s.getBytes(StandardCharsets.UTF_8)); + } os.flush(); is.close(); os.close(); @@ -191,12 +192,12 @@ public class MtomServerTest extends AbstractBusClientServerTestBase { assertEquals(1, attachments.size()); Attachment inAtt = attachments.iterator().next(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); - out.close(); - assertTrue("Wrong size: " + out.size() - + "\n" + out.toString(), - out.size() > 970 && out.size() < 1020); + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + IOUtils.copy(inAtt.getDataHandler().getInputStream(), out); + assertTrue("Wrong size: " + out.size() + + "\n" + out.toString(), + out.size() > 970 && out.size() < 1020); + } unregisterServStatic("http://localhost:" + PORT2 + "/policy.xsd"); }