cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/6] cxf git commit: Stream cleanup [Forced Update!]
Date Mon, 18 Apr 2016 23:24:07 GMT
Repository: cxf
Updated Branches:
  refs/heads/master-jaxrs-2.1 4f82015d2 -> 6eddeb195 (forced update)


Stream cleanup


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d1513222
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d1513222
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d1513222

Branch: refs/heads/master-jaxrs-2.1
Commit: d151322220de948dea0539d5077354c988db80fb
Parents: c94d8b2
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon Apr 18 11:39:17 2016 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Mon Apr 18 11:39:17 2016 +0100

----------------------------------------------------------------------
 .../common/toolspec/AbstractToolContainer.java  |  6 +--
 .../toolspec/parser/CommandLineParser.java      | 44 +++++++++++---------
 .../toolspec/parser/CommandLineParserTest.java  | 13 +++---
 3 files changed, 35 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d1513222/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
----------------------------------------------------------------------
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
index 263621c..d26c3ef 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/AbstractToolContainer.java
@@ -83,7 +83,7 @@ public abstract class AbstractToolContainer implements ToolContainer {
         }        
     }
     
-    public void parseCommandLine() throws BadUsageException {
+    public void parseCommandLine() throws BadUsageException, IOException {
         if (toolspec != null) {
             parser = new CommandLineParser(toolspec);
             commandDoc = parser.parseArguments(arguments);           
@@ -176,8 +176,8 @@ public abstract class AbstractToolContainer implements ToolContainer {
         init();
         try {
             parseCommandLine();
-        } catch (BadUsageException bue) {
-            throw new ToolException(bue);
+        } catch (BadUsageException | IOException e) {
+            throw new ToolException(e);
         }        
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/d1513222/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
----------------------------------------------------------------------
diff --git a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
index 7da11ef..967f4be 100644
--- a/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
+++ b/tools/common/src/main/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParser.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.tools.common.toolspec.parser;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -68,11 +69,11 @@ public class CommandLineParser {
         return res.toArray(new String[res.size()]);
     }
 
-    public CommandDocument parseArguments(String args) throws BadUsageException {
+    public CommandDocument parseArguments(String args) throws BadUsageException, IOException
{
         return parseArguments(getArgsFromString(args));
     }
 
-    public CommandDocument parseArguments(String[] args) throws BadUsageException {
+    public CommandDocument parseArguments(String[] args) throws BadUsageException, IOException
{
 
         if (LOG.isLoggable(Level.FINE)) {
             StringBuilder debugMsg = new StringBuilder("Parsing arguments: ");
@@ -185,9 +186,10 @@ public class CommandLineParser {
                                     new StreamSource(Tool.class
                                         .getResourceAsStream("indent-no-xml-declaration.xsl")));
 
-                OutputStream os = new ByteArrayOutputStream();
-                serializer.transform(new DOMSource(resultDoc), new StreamResult(os));
-                LOG.fine(os.toString());
+                try (OutputStream os = new ByteArrayOutputStream()) {
+                    serializer.transform(new DOMSource(resultDoc), new StreamResult(os));
+                    LOG.fine(os.toString());
+                }
             } catch (Exception ex) {
                 LOG.log(Level.SEVERE, "ERROR_SERIALIZE_COMMAND_MSG", ex);
             }
@@ -196,7 +198,7 @@ public class CommandLineParser {
         return new CommandDocument(toolspec, resultDoc);
     }
 
-    public void throwUsage(ErrorVisitor errors) throws BadUsageException {
+    public void throwUsage(ErrorVisitor errors) throws BadUsageException, IOException {
         try {
             throw new BadUsageException(getUsage(), errors);
         } catch (TransformerException ex) {
@@ -205,28 +207,32 @@ public class CommandLineParser {
         }
     }
 
-    public String getUsage() throws TransformerException {
+    public String getUsage() throws TransformerException, IOException {
         // REVISIT: style usage document into a form more readily output as a
         // usage message
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        InputStream in = getClass().getResourceAsStream("usage.xsl");
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            InputStream in = getClass().getResourceAsStream("usage.xsl");
 
-        toolspec.transform(in, baos);
-        return baos.toString();
+            toolspec.transform(in, baos);
+            return baos.toString();
+        }
     }
 
-    public String getDetailedUsage() throws TransformerException {
+    public String getDetailedUsage() throws TransformerException, IOException {
         // REVISIT: style usage document into a form more readily output as a
         // usage message
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
-        return baos.toString();
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
+            return baos.toString();
+        }
     }
 
-    public String getFormattedDetailedUsage() throws TransformerException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
-        String usage = baos.toString();
+    public String getFormattedDetailedUsage() throws TransformerException, IOException {
+        String usage = null;
+        try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
+            toolspec.transform(getClass().getResourceAsStream("detailedUsage.xsl"), baos);
+            usage = baos.toString();
+        }
         // we use the following pattern to format usage
         // |-------|-options|------|description-----------------|
         // before option white space size is 7

http://git-wip-us.apache.org/repos/asf/cxf/blob/d1513222/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
----------------------------------------------------------------------
diff --git a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
index 9ca2489..8019ada 100644
--- a/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
+++ b/tools/common/src/test/java/org/apache/cxf/tools/common/toolspec/parser/CommandLineParserTest.java
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.tools.common.toolspec.parser;
 
+import java.io.IOException;
 import java.util.StringTokenizer;
 
 import org.apache.cxf.common.util.StringUtils;
@@ -97,7 +98,7 @@ public class CommandLineParserTest extends Assert {
     }
 
     @Test
-    public void testInvalidOption() {
+    public void testInvalidOption() throws IOException {
         try {
             String[] args = new String[] {"-n", "-r", "arg1"};
             parser.parseArguments(args);
@@ -119,7 +120,7 @@ public class CommandLineParserTest extends Assert {
     }
 
     @Test
-    public void testMissingOption() {
+    public void testMissingOption() throws IOException {
         try {
             String[] args = new String[] {"-n", "test", "arg1"};
             parser.parseArguments(args);
@@ -138,7 +139,7 @@ public class CommandLineParserTest extends Assert {
     }
 
     @Test
-    public void testMissingArgument() {
+    public void testMissingArgument() throws IOException {
         try {
             String[] args = new String[] {"-n", "test", "-r"};
             parser.parseArguments(args);
@@ -157,7 +158,7 @@ public class CommandLineParserTest extends Assert {
     }
 
     @Test
-    public void testDuplicateArgument() {
+    public void testDuplicateArgument() throws IOException {
         try {
             String[] args = new String[] {"-n", "test", "-r", "arg1", "arg2"};
             parser.parseArguments(args);
@@ -171,7 +172,7 @@ public class CommandLineParserTest extends Assert {
     }
 
     @Test
-    public void testUnexpectedOption() {
+    public void testUnexpectedOption() throws IOException {
         try {
             String[] args = new String[] {"-n", "test", "-r", "-unknown"};
             parser.parseArguments(args);
@@ -191,7 +192,7 @@ public class CommandLineParserTest extends Assert {
 
 
     @Test
-    public void testInvalidPackageName() {
+    public void testInvalidPackageName() throws IOException {
 
         try {
             String[] args = new String[]{


Mime
View raw message