@Override public void writeTo(OutputStream out) throws IOException, MessagingException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out), 1024); if (preamble != null) { out.write(preamble); writer.write("\r\n"); } if (getBodyParts().isEmpty()) { writer.write("--"); writer.write(boundary); writer.write("\r\n"); } else { for (BodyPart bodyPart : getBodyParts()) { writer.write("--"); writer.write(boundary); writer.write("\r\n"); writer.flush(); bodyPart.writeTo(out); writer.write("\r\n"); } } writer.write("--"); writer.write(boundary); writer.write("--\r\n"); writer.flush(); if (epilogue != null) { out.write(epilogue); } }
private void processSignedMessageAndCaptureMocks(Message message, BodyPart signedBodyPart, OutputStream outputStream) throws Exception { messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback, null, true); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); ArgumentCaptor<OpenPgpDataSource> dataSourceCaptor = ArgumentCaptor.forClass(OpenPgpDataSource.class); ArgumentCaptor<IOpenPgpSinkResultCallback> callbackCaptor = ArgumentCaptor.forClass(IOpenPgpSinkResultCallback.class); verify(openPgpApi).executeApiAsync(intentCaptor.capture(), dataSourceCaptor.capture(), callbackCaptor.capture()); capturedApiIntent = intentCaptor.getValue(); capturedCallback = callbackCaptor.getValue(); OpenPgpDataSource dataSource = dataSourceCaptor.getValue(); dataSource.writeTo(outputStream); verify(signedBodyPart).writeTo(outputStream); }
@Override public void writeTo(OutputStream os) throws IOException { try { Multipart multipartSignedMultipart = (Multipart) signedPart.getBody(); BodyPart signatureBodyPart = multipartSignedMultipart.getBodyPart(0); Timber.d("signed data type: %s", signatureBodyPart.getMimeType()); signatureBodyPart.writeTo(os); } catch (MessagingException e) { Timber.e(e, "Exception while writing message to crypto provider"); } } };