Search in sources :

Example 26 with Converter

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

the class GoogleDriveFilesConverter method genericFileToGoogleDriveFile.

@Converter
public static com.google.api.services.drive.model.File genericFileToGoogleDriveFile(GenericFile<?> file, Exchange exchange) throws Exception {
    if (file.getFile() instanceof File) {
        File f = (File) file.getFile();
        com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
        fileMetadata.setTitle(f.getName());
        FileContent mediaContent = new FileContent(null, f);
        if (exchange != null) {
            exchange.getIn().setHeader("CamelGoogleDrive.content", fileMetadata);
            exchange.getIn().setHeader("CamelGoogleDrive.mediaContent", mediaContent);
        }
        return fileMetadata;
    }
    if (exchange != null) {
        // body wasn't a java.io.File so let's try to convert it
        file.getBinding().loadContent(exchange, file);
        InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, exchange, file.getBody());
        com.google.api.services.drive.model.File fileMetadata = new com.google.api.services.drive.model.File();
        fileMetadata.setTitle(file.getFileName());
        InputStreamContent mediaContent = new InputStreamContent(null, is);
        if (exchange != null) {
            exchange.getIn().setHeader("CamelGoogleDrive.content", fileMetadata);
            exchange.getIn().setHeader("CamelGoogleDrive.mediaContent", mediaContent);
        }
        return fileMetadata;
    }
    return null;
}
Also used : FileContent(com.google.api.client.http.FileContent) InputStream(java.io.InputStream) InputStreamContent(com.google.api.client.http.InputStreamContent) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File) Converter(org.apache.camel.Converter)

Example 27 with Converter

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

the class JcloudsPayloadConverter method toPayload.

@Converter
public static Payload toPayload(final InputStream is, Exchange exchange) throws IOException {
    InputStreamPayload payload = new InputStreamPayload(is);
    // only set the contentlength if possible
    if (is.markSupported()) {
        long contentLength = ByteStreams.length(new InputSupplier<InputStream>() {

            @Override
            public InputStream getInput() throws IOException {
                return is;
            }
        });
        is.reset();
        payload.getContentMetadata().setContentLength(contentLength);
    }
    return payload;
}
Also used : InputStream(java.io.InputStream) InputStreamPayload(org.jclouds.io.payloads.InputStreamPayload) IOException(java.io.IOException) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

Example 28 with Converter

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

the class MinaConverter method toByteBuffer.

@Converter
public static ByteBuffer toByteBuffer(byte[] bytes) {
    ByteBuffer buf = ByteBuffer.allocate(bytes.length);
    buf.put(bytes);
    return buf;
}
Also used : ByteBuffer(org.apache.mina.common.ByteBuffer) Converter(org.apache.camel.Converter)

Example 29 with Converter

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

the class Mina2Converter method toIoBuffer.

@Converter
public static IoBuffer toIoBuffer(byte[] bytes) {
    IoBuffer buf = IoBuffer.allocate(bytes.length);
    buf.put(bytes);
    return buf;
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer) Converter(org.apache.camel.Converter)

Example 30 with Converter

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

the class SaxonConverter method toDOMDocument.

@Converter
public static Document toDOMDocument(NodeInfo node) throws XPathException {
    switch(node.getNodeKind()) {
        case Type.DOCUMENT:
            // DOCUMENT type nodes can be wrapped directly
            return (Document) NodeOverNodeInfo.wrap(node);
        case Type.ELEMENT:
            // ELEMENT nodes need to build a new DocumentInfo before wrapping
            Configuration config = node.getConfiguration();
            DocumentInfo documentInfo = config.buildDocument(node);
            return (Document) NodeOverNodeInfo.wrap(documentInfo);
        default:
            return null;
    }
}
Also used : Configuration(net.sf.saxon.Configuration) Document(org.w3c.dom.Document) DocumentInfo(net.sf.saxon.om.DocumentInfo) FallbackConverter(org.apache.camel.FallbackConverter) Converter(org.apache.camel.Converter) TypeConverter(org.apache.camel.TypeConverter)

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