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