You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/02/13 16:18:04 UTC

svn commit: r744142 - in /camel/branches/camel-1.x: ./ camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Author: davsclaus
Date: Fri Feb 13 15:18:02 2009
New Revision: 744142

URL: http://svn.apache.org/viewvc?rev=744142&view=rev
Log:
Merged revisions 744123 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r744123 | davsclaus | 2009-02-13 15:28:33 +0100 (Fri, 13 Feb 2009) | 1 line
  
  Closing streams.
........

Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Feb 13 15:18:02 2009
@@ -1 +1 @@
-/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960
+/camel/trunk:739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=744142&r1=744141&r2=744142&view=diff
==============================================================================
--- camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Fri Feb 13 15:18:02 2009
@@ -42,7 +42,6 @@
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
 import java.net.URL;
-
 import javax.xml.transform.TransformerException;
 import javax.xml.transform.dom.DOMSource;
 
@@ -50,6 +49,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.converter.jaxp.XmlConverter;
 import org.apache.camel.util.CollectionStringBuffer;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -123,7 +123,7 @@
                 try {
                     return toInputStream(text.getBytes(charsetName));
                 } catch (UnsupportedEncodingException e) {
-                    LOG.warn("Can't convert the String into the bytes with the charset " + charsetName, e);
+                    LOG.warn("Cannot convert the String into byte[] with the charset: " + charsetName, e);
                 }
             }
         }
@@ -157,7 +157,7 @@
                 try {
                     return new String(data, charsetName);
                 } catch (UnsupportedEncodingException e) {
-                    LOG.warn("Can't convert the byte to String with the charset " + charsetName, e);
+                    LOG.warn("Cannot convert the byte[] to String with the charset: " + charsetName, e);
                 }
             }
         }
@@ -213,11 +213,7 @@
                 builder.append(line);
             }
         } finally {
-            try {
-                reader.close();
-            } catch (IOException e) {
-                LOG.warn("Failed to close stream: " + e, e);
-            }
+            ObjectHelper.close(reader, "reader", LOG);
         }
     }
 
@@ -235,12 +231,9 @@
                 sb.append(buf, 0, len);
             }
         } finally {
-            try {
-                reader.close();
-            } catch (IOException e) {
-                LOG.warn("Failed to close stream: " + e, e);
-            }
+            ObjectHelper.close(reader, "reader", LOG);
         }
+
         return sb.toString().getBytes();
     }
 
@@ -275,8 +268,12 @@
     @Converter
     public static byte[] toBytes(InputStream stream) throws IOException {
         ByteArrayOutputStream bos = new ByteArrayOutputStream();
-        copy(stream, bos);
-        return bos.toByteArray();
+        try {
+            copy(stream, bos);
+            return bos.toByteArray();
+        } finally {
+            ObjectHelper.close(bos, "stream", LOG);
+        }
     }
 
     public static void copy(InputStream stream, OutputStream os) throws IOException {