camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7100 Fixed the Scaner close issue in JDK7
Date Fri, 03 Jan 2014 07:24:24 GMT
CAMEL-7100 Fixed the Scaner close issue in JDK7

Conflicts:
	camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java


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

Branch: refs/heads/camel-2.11.x
Commit: 12f1adf203517505ce4cd6461615540f0c02dab5
Parents: 1c06089
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Fri Jan 3 14:24:34 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Fri Jan 3 15:23:55 2014 +0800

----------------------------------------------------------------------
 .../org/apache/camel/processor/Splitter.java    | 11 +++++----
 .../org/apache/camel/util/GroupIterator.java    | 26 +++++++++++++-------
 .../java/org/apache/camel/util/IOHelper.java    | 17 +++++++++++++
 .../SplitterWithScannerIoExceptionTest.java     |  4 +--
 4 files changed, 42 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/12f1adf2/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/Splitter.java b/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
index 8c9e69f..0bef536 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/Splitter.java
@@ -192,19 +192,20 @@ public class Splitter extends MulticastProcessor implements AsyncProcessor,
Trac
 
         @Override
         public void close() throws IOException {
-            if (value instanceof Closeable) {
-                IOHelper.close((Closeable) value, value.getClass().getName(), LOG);
-            } else if (value instanceof Scanner) {
-                // special for Scanner as it does not implement Closeable
+            if (value instanceof Scanner) {
+                // special for Scanner which implement the Closeable since JDK7 
                 Scanner scanner = (Scanner) value;
                 scanner.close();
-
                 IOException ioException = scanner.ioException();
                 if (ioException != null) {
                     throw ioException;
                 }
+            } else if (value instanceof Closeable) {
+                // we should throw out the exception here   
+                IOHelper.closeWithException((Closeable) value);
             }
         }
+       
     }
 
     private Iterable<ProcessorExchangePair> createProcessorExchangePairsList(Exchange
exchange, Object value) {

http://git-wip-us.apache.org/repos/asf/camel/blob/12f1adf2/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java b/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java
index 95a5a1e..158dbed 100644
--- a/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java
+++ b/camel-core/src/main/java/org/apache/camel/util/GroupIterator.java
@@ -65,16 +65,24 @@ public final class GroupIterator implements Iterator<Object>, Closeable
{
 
     @Override
     public void close() throws IOException {
-        if (it instanceof Closeable) {
-            IOHelper.close((Closeable) it);
-        } else if (it instanceof Scanner) {
-            // special for Scanner as it does not implement Closeable
-            ((Scanner) it).close();
+        try {
+            if (it instanceof Scanner) {
+                // special for Scanner which implement the Closeable since JDK7 
+                Scanner scanner = (Scanner) it;
+                scanner.close();
+                IOException ioException = scanner.ioException();
+                if (ioException != null) {
+                    throw ioException;
+                }
+            } else if (it instanceof Closeable) {
+                IOHelper.closeWithException((Closeable) it);
+            }
+        } finally {
+            // close the buffer as well
+            bos.close();
+            // we are now closed
+            closed = true;
         }
-        // close the buffer as well
-        bos.close();
-        // we are now closed
-        closed = true;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/12f1adf2/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
index e2fdfaf..d5fa300 100644
--- a/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/IOHelper.java
@@ -310,6 +310,23 @@ public final class IOHelper {
             }
         }
     }
+    
+    /**
+     * Closes the given resource if it is available and don't catch the exception
+     *
+     * @param closeable the object to close
+     * @throws IOException
+      */
+    public static void closeWithException(Closeable closeable) throws IOException {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            } catch (IOException e) {
+                // don't catch the exception here
+                throw e;
+            }
+        }
+    }
 
     /**
      * Closes the given channel if it is available, logging any closing exceptions to the
given log.

http://git-wip-us.apache.org/repos/asf/camel/blob/12f1adf2/camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java
b/camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java
index a4e1d00..e158413 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/SplitterWithScannerIoExceptionTest.java
@@ -22,7 +22,7 @@ import org.apache.camel.builder.RouteBuilder;
 public class SplitterWithScannerIoExceptionTest extends ContextTestSupport {
 
     public void testSplitterStreamingWithError() throws Exception {
-        if (isJavaVersion("1.7")) {
+        if (isPlatform("aix") || isJavaVendor("ibm")) {
             return;
         }
 
@@ -50,4 +50,4 @@ public class SplitterWithScannerIoExceptionTest extends ContextTestSupport
{
             }
         };
     }
-}
\ No newline at end of file
+}


Mime
View raw message