@Override public Object unmarshal(final Exchange exchange, final InputStream inputStream) throws Exception { if (usingIterator) { ZipIterator zipIterator = new ZipIterator(exchange, inputStream); 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); } } }
private Map.Entry<String, Object> downloadSingleFile(String path) throws DropboxException { try { OutputStreamBuilder target = OutputStreamBuilder.withExchange(exchange); DbxDownloader<FileMetadata> downloadedFile = client.files().download(path); if (downloadedFile != null) { downloadedFile.download(target); 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 cannot obtain metadata", e); } catch (IOException e) { throw new DropboxException(path + " cannot obtain a stream", e); } } }
private Object transformToStreamCacheOrByteArray(Exchange exchange, InputStream is) throws CryptoCmsException { // the input stream must be completely read, outherwise you will get // errors when your use as next component the file adapter. OutputStreamBuilder output = OutputStreamBuilder.withExchange(exchange); try { // data can be null in the case of explicit Signed Data if (is != null) { try { IOHelper.copy(is, output); } finally { IOHelper.close(is); } } LOG.debug("CMS Enveloped Data decryption successful"); return output.build(); } catch (IOException e) { throw new CryptoCmsException("Error during reading the unencrypted content of the enveloped data object", e); } finally { IOHelper.close(output); } }
@Override public Object unmarshal(final Exchange exchange, final InputStream stream) throws Exception { if (usingIterator) { TarIterator tarIterator = new TarIterator(exchange, stream); tarIterator.setAllowEmptyDirectory(allowEmptyDirectory); return tarIterator; } 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); } } }
@Override public void process(Exchange exchange) throws Exception { // NOPMD all // exceptions must be caught to react on exception case and re-thrown, // see code below OutputStreamBuilder output = OutputStreamBuilder.withExchange(exchange); OutputStream outStream; if (config.getToBase64()) { outStream = new Base64OutputStream(output); } else { outStream = output; } InputStream body = exchange.getIn().getMandatoryBody(InputStream.class); // lets setup the out message before we invoke the processing // so that it can mutate it if necessary Message out = exchange.getOut(); out.copyFrom(exchange.getIn()); try { try { marshalInternal(body, outStream, exchange); } finally { IOHelper.close(outStream); // base64 stream must be closed, // before we fetch the bytes } setBodyAndHeader(out, output.build()); } catch (Throwable e) { // remove OUT message, as an exception occurred exchange.setOut(null); throw e; } }
@Override protected Object unmarshalInternal(InputStream is, Exchange exchange) throws Exception { CMSSignedDataParser sp; try { sp = new CMSSignedDataParser(new JcaDigestCalculatorProviderBuilder().setProvider(BouncyCastleProvider.PROVIDER_NAME).build(), is); } catch (CMSException e) { throw new CryptoCmsFormatException(getFormatErrorMessage(), e); } OutputStreamBuilder output = getOutputStream(sp, exchange); debugLog(sp); verify(sp, exchange); return output.build(); }
public Object unmarshal(final Exchange exchange, final InputStream encryptedStream) throws Exception { if (encryptedStream != null) { byte[] iv = getInlinedInitializationVector(exchange, encryptedStream); Key key = getKey(exchange); CipherInputStream cipherStream = null; OutputStreamBuilder osb = null; try { cipherStream = new CipherInputStream(encryptedStream, initializeCipher(DECRYPT_MODE, key, iv)); osb = OutputStreamBuilder.withExchange(exchange); HMACAccumulator hmac = getMessageAuthenticationCode(key); byte[] buffer = new byte[bufferSize]; hmac.attachStream(osb); int read; while ((read = cipherStream.read(buffer)) >= 0) { hmac.decryptUpdate(buffer, read); } hmac.validate(); return osb.build(); } finally { IOHelper.close(cipherStream, "cipher", LOG); IOHelper.close(osb, "plaintext", LOG); } } return null; }
return osb.build();