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;
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations