Reputation: 55
I have an requirement to move the files from one S3 bucket to another S3 bucket, during this process I need to split the file (that is an image file).
So, this is how I am doing
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(sourcePoint.getS3SourcePoint()).split().method(new SheetImageSplitterImpl(), "split").to(destinationPoint.getS3DestinationPoint());
}
});
camelContext.start();
Inside SheetImageSplitter's split()
method, I am trying to implement the logic to split the image file. The exchange body returns me a body of type S3Object.inputStream. I do not find any help to convert the S3ObjectInputStream to image files
public List<Message> split(Exchange exchange) {
System.out.println(exchange.getIn().getBody());
}
Is there way, So that I can process the image files
Note : I am using Java DSL
Upvotes: 2
Views: 720
Reputation: 751
You can convert that S3ObjectInputStream
as InputStream
and put it back into the message
public List<message> split(Exchange exchange){
InputStream iStream = (InputStream) exchange.getIn().getBody();
File file = new File("tmp/filename.jpg");
FileUtils.copyInputStreamToFile(iStream, file);
List<File> files = <your splitting logic method>
List<Message> messageList = new ArrayList<Message>();
for (File file : files) {
DefaultMessage message = new DefaultMessage();
InputStream ip = new FileInputStream(file.getName());
message.setBody((InputStream) ip);
messageList.add(message);
}
return messageList;
}
Upvotes: 1
Reputation: 7646
Why do you need to split an image file? I don't know S3, but following code should create an image file:
BufferedImage imBuff = ImageIO.read(inputStream);
Hope, it helps.
Upvotes: 1