Search in sources :

Example 11 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class XmlConverter method toStreamSourceFromSAX.

@Converter
public StreamSource toStreamSourceFromSAX(SAXSource source, Exchange exchange) throws TransformerException {
    InputSource inputSource = source.getInputSource();
    if (inputSource != null) {
        if (inputSource.getCharacterStream() != null) {
            return new StreamSource(inputSource.getCharacterStream());
        }
        if (inputSource.getByteStream() != null) {
            return new StreamSource(inputSource.getByteStream());
        }
    }
    String result = toString(source, exchange);
    return new StringSource(result);
}
Also used : InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) StringSource(org.apache.camel.StringSource) Converter(org.apache.camel.Converter)

Example 12 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class CamelConverter method toProcessor.

@Converter
public static Processor toProcessor(final Predicate predicate) {
    return new Processor() {

        public void process(Exchange exchange) throws Exception {
            boolean answer = predicate.matches(exchange);
            Message out = exchange.getOut();
            out.copyFrom(exchange.getIn());
            out.setBody(answer);
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(org.apache.camel.Message) Converter(org.apache.camel.Converter)

Example 13 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class NIOConverter method toByteBuffer.

@Converter
public static ByteBuffer toByteBuffer(Float value) {
    ByteBuffer buf = ByteBuffer.allocate(4);
    buf.putFloat(value);
    buf.flip();
    return buf;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Converter(org.apache.camel.Converter)

Example 14 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class NIOConverter method toByteBuffer.

@Converter
public static ByteBuffer toByteBuffer(Long value) {
    ByteBuffer buf = ByteBuffer.allocate(8);
    buf.putLong(value);
    buf.flip();
    return buf;
}
Also used : ByteBuffer(java.nio.ByteBuffer) Converter(org.apache.camel.Converter)

Example 15 with Converter

use of org.apache.camel.Converter in project camel by apache.

the class NIOConverter method toByteBuffer.

@Converter
public static ByteBuffer toByteBuffer(File file) throws IOException {
    InputStream in = null;
    try {
        byte[] buf = new byte[(int) file.length()];
        in = IOHelper.buffered(new FileInputStream(file));
        int sizeLeft = (int) file.length();
        int offset = 0;
        while (sizeLeft > 0) {
            int readSize = in.read(buf, offset, sizeLeft);
            sizeLeft -= readSize;
            offset += readSize;
        }
        return ByteBuffer.wrap(buf);
    } finally {
        IOHelper.close(in, "Failed to close file stream: " + file.getPath(), LOG);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileInputStream(java.io.FileInputStream) Converter(org.apache.camel.Converter)

Aggregations

Converter (org.apache.camel.Converter)71 TypeConverter (org.apache.camel.TypeConverter)11 FallbackConverter (org.apache.camel.FallbackConverter)10 InputStream (java.io.InputStream)8 ByteBuffer (java.nio.ByteBuffer)7 IOConverter (org.apache.camel.converter.IOConverter)7 InputSource (org.xml.sax.InputSource)6 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 List (java.util.List)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringReader (java.io.StringReader)4 ArrayList (java.util.ArrayList)4 FileInputStream (java.io.FileInputStream)3 XMLStreamReader (javax.xml.stream.XMLStreamReader)3 SAXSource (javax.xml.transform.sax.SAXSource)3 MultiSearchRequest (org.elasticsearch.action.search.MultiSearchRequest)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 Document (org.w3c.dom.Document)3 Element (org.w3c.dom.Element)3