private void marshalUrlSafe(Exchange exchange, Object graph, OutputStream stream) throws Exception { byte[] decoded = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, graph); Base64 codec = new Base64(lineLength, lineSeparator, true); byte[] encoded = codec.encode(decoded); stream.write(encoded); stream.flush(); }
public void calculateSignature(Exchange exchange, Signature signer) throws Exception { Object payload = exchange.getIn().getBody(); if (payload != null) { InputStream payloadStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, payload); try { byte[] buffer = new byte[config.getBufferSize()]; int read; while ((read = payloadStream.read(buffer)) > 0) { signer.update(buffer, 0, read); } } finally { IOHelper.close(payloadStream); } } }
/** * Writes the given row. * * @param exchange exchange to use (for type conversion) * @param row row to write * @param writer uniVocity writer to use * @throws NoTypeConversionAvailableException when it's not possible to * convert the row as map. */ private void writeRow(Exchange exchange, Object row, W writer) throws NoTypeConversionAvailableException { Map<?, ?> map = convertToMandatoryType(exchange, Map.class, row); if (adaptHeaders) { synchronized (headers) { for (Object key : map.keySet()) { headers.add(convertToMandatoryType(exchange, String.class, key)); } writeRow(map, writer); } } else { writeRow(map, writer); } }
private void marshalStreaming(Exchange exchange, Object graph, OutputStream stream) throws Exception { InputStream decoded = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph); Base64OutputStream base64Output = new Base64OutputStream(stream, true, lineLength, lineSeparator); try { IOHelper.copy(decoded, base64Output); } finally { IOHelper.close(decoded, base64Output); } }
private Iterable<?> getRecordValues(Exchange exchange, Object data) throws NoTypeConversionAvailableException { // each row must be a map or list based Map<?, ?> map = exchange.getContext().getTypeConverter().tryConvertTo(Map.class, exchange, data); if (map != null) { return getMapRecordValues(map); } return ExchangeHelper.convertToMandatoryType(exchange, List.class, data); }
byte[] bodyContent = ExchangeHelper.convertToMandatoryType(exchange, byte[].class, graph); Session session = Session.getInstance(System.getProperties()); MimeMessage mm = new MimeMessage(session); } else { InputStream is = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph); IOHelper.copyAndCloseInput(is, stream);
InputStream input = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
public void marshal(Exchange exchange, Object graph, OutputStream outputStream) throws Exception { byte[] iv = getInitializationVector(exchange); Key key = getKey(exchange); InputStream plaintextStream = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph); HMACAccumulator hmac = getMessageAuthenticationCode(key); if (plaintextStream != null) { inlineInitVector(outputStream, iv); byte[] buffer = new byte[bufferSize]; int read; CipherOutputStream cipherStream = null; try { cipherStream = new CipherOutputStream(outputStream, initializeCipher(ENCRYPT_MODE, key, iv)); while ((read = plaintextStream.read(buffer)) > 0) { cipherStream.write(buffer, 0, read); cipherStream.flush(); hmac.encryptUpdate(buffer, read); } // only write if there is data to write (IBM JDK throws exception if no data) byte[] mac = hmac.getCalculatedMac(); if (mac != null && mac.length > 0) { cipherStream.write(mac); } } finally { IOHelper.close(cipherStream, "cipher", LOG); IOHelper.close(plaintextStream, "plaintext", LOG); } } }
/** * Writes the image file to the output stream. * * @param graph the object graph * @param exchange the camel exchange * @param stream the output stream */ private void printImage(final Exchange exchange, final Object graph, final OutputStream stream) throws Exception { final String payload = ExchangeHelper .convertToMandatoryType(exchange, String.class, graph); final MultiFormatWriter writer = new MultiFormatWriter(); // set values final String type = this.params.getType().toString(); // create code image final BitMatrix matrix = writer.encode( payload, this.params.getFormat(), this.params.getWidth(), this.params.getHeight(), writerHintMap); // write image back to stream MatrixToImageWriter.writeToStream(matrix, type, stream); }