use of org.apache.camel.converter.stream.OutputStreamBuilder in project camel by apache.
the class LZFDataFormat method unmarshal.
@Override
public Object unmarshal(final Exchange exchange, final InputStream inputStream) throws Exception {
InputStream compressedInput = null;
OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
try {
compressedInput = new LZFInputStream(inputStream);
IOHelper.copy(compressedInput, osb);
return osb.build();
} finally {
// must close all input streams
IOHelper.close(osb, compressedInput, inputStream);
}
}
use of org.apache.camel.converter.stream.OutputStreamBuilder in project camel by apache.
the class ZipFileDataFormat method unmarshal.
@Override
public Object unmarshal(final Exchange exchange, final InputStream inputStream) throws Exception {
if (usingIterator) {
ZipIterator zipIterator = new ZipIterator(exchange.getIn());
zipIterator.setAllowEmptyDirectory(allowEmptyDirectory);
return zipIterator;
} else {
ZipInputStream zis = new ZipInputStream(inputStream);
OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
try {
ZipEntry entry = zis.getNextEntry();
if (entry != null) {
exchange.getOut().setHeader(FILE_NAME, entry.getName());
IOHelper.copy(zis, osb);
}
entry = zis.getNextEntry();
if (entry != null) {
throw new IllegalStateException("Zip file has more than 1 entry.");
}
return osb.build();
} finally {
IOHelper.close(zis, osb);
}
}
}
use of org.apache.camel.converter.stream.OutputStreamBuilder in project camel by apache.
the class TarFileDataFormat method unmarshal.
@Override
public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception {
if (usingIterator) {
return new TarIterator(exchange.getIn(), stream);
} else {
BufferedInputStream bis = new BufferedInputStream(stream);
TarArchiveInputStream tis = (TarArchiveInputStream) new ArchiveStreamFactory().createArchiveInputStream(ArchiveStreamFactory.TAR, bis);
OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
try {
TarArchiveEntry entry = tis.getNextTarEntry();
if (entry != null) {
exchange.getOut().setHeader(FILE_NAME, entry.getName());
IOHelper.copy(tis, osb);
}
entry = tis.getNextTarEntry();
if (entry != null) {
throw new IllegalStateException("Tar file has more than 1 entry.");
}
return osb.build();
} finally {
IOHelper.close(osb, tis, bis);
}
}
}
use of org.apache.camel.converter.stream.OutputStreamBuilder in project camel by apache.
the class DropboxAPIFacade method downloadSingleFile.
private Map.Entry<String, Object> downloadSingleFile(String path) throws DropboxException {
try {
OutputStreamBuilder target = OutputStreamBuilder.withExchange(exchange);
DbxEntry.File downloadedFile = client.getFile(path, null, target);
if (downloadedFile != null) {
LOG.debug("downloaded path={}", path);
return new AbstractMap.SimpleEntry<>(path, target.build());
} else {
return null;
}
} catch (DbxException e) {
throw new DropboxException(path + " does not exist or can't obtain metadata");
} catch (IOException e) {
throw new DropboxException(path + " can't obtain a stream");
}
}
use of org.apache.camel.converter.stream.OutputStreamBuilder in project camel by apache.
the class MarshalProcessor method process.
public boolean process(Exchange exchange, AsyncCallback callback) {
ObjectHelper.notNull(dataFormat, "dataFormat");
// if stream caching is enabled then use that so we can stream accordingly
// for example to overflow to disk for big streams
OutputStreamBuilder osb = OutputStreamBuilder.withExchange(exchange);
Message in = exchange.getIn();
Object body = in.getBody();
// lets setup the out message before we invoke the dataFormat
// so that it can mutate it if necessary
Message out = exchange.getOut();
out.copyFrom(in);
try {
dataFormat.marshal(exchange, body, osb);
out.setBody(osb.build());
} catch (Throwable e) {
// remove OUT message, as an exception occurred
exchange.setOut(null);
exchange.setException(e);
}
callback.done(true);
return true;
}
Aggregations