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 15:28:35 UTC

svn commit: r744123 - /camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Author: davsclaus
Date: Fri Feb 13 14:28:33 2009
New Revision: 744123

URL: http://svn.apache.org/viewvc?rev=744123&view=rev
Log:
Closing streams.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?rev=744123&r1=744122&r2=744123&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java Fri Feb 13 14:28:33 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);
+        }
     }
 
     @Converter