Author: davsclaus Date: Mon Mar 2 08:48:10 2009 New Revision: 749236 URL: http://svn.apache.org/viewvc?rev=749236&view=rev Log: CAMEL-588: Fixed bad package tangle.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java camel/trunk/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/builder/xml/XPathBuilder.java Mon Mar 2 08:48:10 2009 @@ -51,7 +51,6 @@ import static org.apache.camel.builder.xml.Namespaces.IN_NAMESPACE; import static org.apache.camel.builder.xml.Namespaces.OUT_NAMESPACE; import static org.apache.camel.builder.xml.Namespaces.isMatchingNamespaceOrEmptyNamespace; -import static org.apache.camel.converter.ObjectConverter.toBoolean; /** * Creates an XPath expression builder which creates a nodeset result by default. @@ -97,12 +96,13 @@ public boolean matches(Exchange exchange) { Object booleanResult = evaluateAs(exchange, XPathConstants.BOOLEAN); - return toBoolean(booleanResult); + return exchange.getContext().getTypeConverter().convertTo(Boolean.class, booleanResult); } public void assertMatches(String text, Exchange exchange) throws AssertionError { Object booleanResult = evaluateAs(exchange, XPathConstants.BOOLEAN); - if (!toBoolean(booleanResult)) { + Boolean answer = exchange.getContext().getTypeConverter().convertTo(Boolean.class, booleanResult); + if (answer == null) { throw new AssertionError(this + " failed on " + exchange + " as returned <" + booleanResult + ">"); } } 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=749236&r1=749235&r2=749236&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 Mon Mar 2 08:48:10 2009 @@ -49,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.IOHelper; import org.apache.camel.util.ObjectHelper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -269,7 +270,7 @@ public static byte[] toBytes(InputStream stream) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { - copy(stream, bos); + IOHelper.copy(stream, bos); return bos.toByteArray(); } finally { ObjectHelper.close(bos, "stream", LOG); @@ -291,14 +292,4 @@ return new ByteArrayInputStream(os.toByteArray()); } - public static void copy(InputStream stream, OutputStream os) throws IOException { - byte[] data = new byte[4096]; - int read = stream.read(data); - while (read != -1) { - os.write(data, 0, read); - read = stream.read(data); - } - os.flush(); - } - } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SerializationDataFormat.java Mon Mar 2 08:48:10 2009 @@ -23,8 +23,8 @@ import java.io.OutputStream; import org.apache.camel.Exchange; -import org.apache.camel.converter.IOConverter; import org.apache.camel.spi.DataFormat; +import org.apache.camel.util.ExchangeHelper; /** * The <a href="http://camel.apache.org/data-format.html">data format</a> @@ -35,7 +35,7 @@ public class SerializationDataFormat implements DataFormat { public void marshal(Exchange exchange, Object graph, OutputStream stream) throws IOException { - ObjectOutput out = IOConverter.toObjectOutput(stream); + ObjectOutput out = ExchangeHelper.convertToType(exchange, ObjectOutput.class, stream); try { out.writeObject(graph); } finally { @@ -49,7 +49,7 @@ } public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, ClassNotFoundException { - ObjectInput in = IOConverter.toObjectInput(stream); + ObjectInput in = ExchangeHelper.convertToType(exchange, ObjectInput.class, stream); try { return in.readObject(); } finally { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/StringDataFormat.java Mon Mar 2 08:48:10 2009 @@ -21,7 +21,6 @@ import java.io.OutputStream; import org.apache.camel.Exchange; -import org.apache.camel.converter.IOConverter; import org.apache.camel.spi.DataFormat; import org.apache.camel.util.ExchangeHelper; @@ -51,8 +50,8 @@ stream.write(bytes); } - public Object unmarshal(Exchange exchange, InputStream stream) throws IOException, ClassNotFoundException { - byte[] bytes = IOConverter.toBytes(stream); + public Object unmarshal(Exchange exchange, InputStream stream) throws IOException { + byte[] bytes = ExchangeHelper.convertToType(exchange, byte[].class, stream); String answer; if (charset != null) { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ZipDataFormat.java Mon Mar 2 08:48:10 2009 @@ -24,9 +24,9 @@ import java.util.zip.InflaterInputStream; import org.apache.camel.Exchange; -import org.apache.camel.converter.IOConverter; import org.apache.camel.spi.DataFormat; import org.apache.camel.util.ExchangeHelper; +import org.apache.camel.util.IOHelper; public class ZipDataFormat implements DataFormat { @@ -40,32 +40,29 @@ this.compressionLevel = compressionLevel; } - public void marshal(Exchange exchange, Object graph, OutputStream stream) - throws Exception { - + public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph); - if (is == null) { - throw new IllegalArgumentException("Cannot get the inputstream for ZipDataFormat mashalling"); - } DeflaterOutputStream zipOutput = new DeflaterOutputStream(stream, new Deflater(compressionLevel)); try { - IOConverter.copy(is, zipOutput); + IOHelper.copy(is, zipOutput); } finally { zipOutput.close(); } } - public Object unmarshal(Exchange exchange, InputStream stream) - throws Exception { - + public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class); InflaterInputStream unzipInput = new InflaterInputStream(is); // Create an expandable byte array to hold the inflated data ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOConverter.copy(unzipInput, bos); - return bos.toByteArray(); + try { + IOHelper.copy(unzipInput, bos); + return bos.toByteArray(); + } finally { + bos.close(); + } } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/IOHelper.java Mon Mar 2 08:48:10 2009 @@ -17,6 +17,8 @@ package org.apache.camel.util; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; /** * IO helper class. @@ -46,4 +48,15 @@ answer.initCause(cause); return answer; } + + public static void copy(InputStream stream, OutputStream os) throws IOException { + byte[] data = new byte[4096]; + int read = stream.read(data); + while (read != -1) { + os.write(data, 0, read); + read = stream.read(data); + } + os.flush(); + } + } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/SystemHelper.java Mon Mar 2 08:48:10 2009 @@ -16,7 +16,6 @@ */ package org.apache.camel.util; -import org.apache.camel.converter.ObjectConverter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,7 +48,8 @@ */ public static boolean isSystemProperty(String name) { String text = getSystemProperty(name); - return ObjectConverter.toBool(text); + Boolean answer = ObjectHelper.toBoolean(text); + return answer != null ? answer : false; } } Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java?rev=749236&r1=749235&r2=749236&view=diff ============================================================================== --- camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java (original) +++ camel/trunk/camel-core/src/test/java/org/apache/camel/converter/IOConverterTest.java Mon Mar 2 08:48:10 2009 @@ -20,10 +20,9 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; import junit.framework.TestCase; +import org.apache.camel.util.IOHelper; /** * Test case for {...@link IOConverter} @@ -32,7 +31,7 @@ private static final byte[] TESTDATA = "My test data".getBytes(); - public void testToBytes() throws FileNotFoundException, IOException { + public void testToBytes() throws Exception { File file = new File("src/test/resources/org/apache/camel/converter/dummy.txt"); byte[] data = IOConverter.toBytes(new FileInputStream(file)); assertEquals("get the wrong byte size", file.length(), data.length); @@ -40,10 +39,10 @@ assertEquals('!', (char) data[data.length - 1]); } - public void testCopy() throws IOException { + public void testCopy() throws Exception { ByteArrayInputStream bis = new ByteArrayInputStream(TESTDATA); ByteArrayOutputStream bos = new ByteArrayOutputStream(); - IOConverter.copy(bis, bos); + IOHelper.copy(bis, bos); assertEquals(TESTDATA, bos.toByteArray()); }