private static void _log (@Nonnull final MimeBodyPart aMimePart, @Nonnull final String sContext) throws IOException, MessagingException { if (false) { LOGGER.info ("[[" + sContext + "]]"); try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { aMimePart.writeTo (aBAOS); LOGGER.info (aBAOS.getAsString (StandardCharsets.ISO_8859_1)); } LOGGER.info ("[[END]]"); } }
/** * Constructs an instance of this class which will trigger an event at the * specified threshold, and save data to a file beyond that point. * * @param nThreshold * The number of bytes at which to trigger an event. * @param aOutputFile * The file to which data is saved beyond the threshold. */ public DeferredFileOutputStream (@Nonnegative final int nThreshold, @Nonnull final File aOutputFile) { super (nThreshold); m_aOutputFile = ValueEnforcer.notNull (aOutputFile, "OutputFile"); m_aMemoryOS = new NonBlockingByteArrayOutputStream (); m_aCurrentOS = m_aMemoryOS; }
@Override public ZipEntry getNextEntry () throws IOException { ZipEntry aZipEntry = super.getNextEntry (); if (aZipEntry != null && aZipEntry.getName ().equals (ZIPENTRY_NAME_MIMETYPE)) { try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ();) { AsicUtils.copyStream (this, aBAOS); final String sMimeType = aBAOS.getAsString (StandardCharsets.ISO_8859_1); if (LOG.isDebugEnabled ()) LOG.debug ("Content of mimetype: " + sMimeType); if (!AsicUtils.MIMETYPE_ASICE.getAsString ().equals (sMimeType)) throw new IllegalStateException ("Content is not ASiC-E container."); } // Fetch next aZipEntry = super.getNextEntry (); } return aZipEntry; } }
public byte [] getAsBytes (@Nonnull final SignatureHelper aSH) { try { final Marshaller aMarshaller = s_aJaxbContext.createMarshaller (); aMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { // TODO aMarshaller.marshal (OF_CADES.createXAdESSignatures (getCreateXAdESSignatures (aSH)), aBAOS); return aBAOS.toByteArray (); } } catch (final JAXBException ex) { throw new IllegalStateException ("Unable to marshall the XAdESSignature into string output", ex); } }
/** * Send a simple HTTP response that only contains the HTTP status code and the * respective descriptive text. An empty header map us used. * * @param aResponseHandler * The response handler to be used. * @param nResponseCode * The HTTP response code to use. * @throws IOException * In case sending fails for whatever reason */ public static void sendSimpleHTTPResponse (@Nonnull final IAS2HttpResponseHandler aResponseHandler, @Nonnegative final int nResponseCode) throws IOException { try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream ()) { final String sHTTPLine = Integer.toString (nResponseCode) + " " + CHttp.getHttpResponseMessage (nResponseCode) + CHttp.EOL; aData.write (sHTTPLine.getBytes (CHttp.HTTP_CHARSET)); aResponseHandler.sendHttpResponse (nResponseCode, new HttpHeaderMap (), aData); } }
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 * CGlobal.BYTES_PER_KILOBYTE))
final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 * CGlobal.BYTES_PER_KILOBYTE))
return null; try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (1024))
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
private void writeObject (@Nonnull final ObjectOutputStream aOOS) throws IOException { // write text aOOS.writeObject (m_sText); // write the mime body final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (); try { if (m_aData != null) { aBAOS.write (1); m_aData.writeTo (aBAOS); } else { aBAOS.write (0); } aBAOS.writeTo (aOOS); } catch (final MessagingException ex) { throw new IOException ("Messaging exception", ex); } finally { StreamHelper.close (aBAOS); } } }
private void writeObject (@Nonnull final ObjectOutputStream aOOS) throws IOException { // write the mime body // Write to BAOS first to avoid serializing an incomplete object try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { try { if (m_aData != null) { aBAOS.write (1); m_aData.writeTo (aBAOS); } else { aBAOS.write (0); } } catch (final MessagingException ex) { throw new IOException ("Messaging exception: " + ex.getMessage ()); } aOOS.write (aBAOS.toByteArray ()); } // write the message's MDN aOOS.writeObject (m_aMDN); }
public void writeFile (final OutputStream aOS) throws IOException { if (m_sCurrentFile.endsWith (".p7m")) { try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { m_aAsicReader.writeFile (aBAOS); final CMSEnvelopedDataParser aCMSEnvelopedDataParser = new CMSEnvelopedDataParser (aBAOS.getAsInputStream ()); // expect exactly one recipient final Collection <RecipientInformation> aRecipients = aCMSEnvelopedDataParser.getRecipientInfos () .getRecipients (); if (aRecipients.size () != 1) throw new IllegalArgumentException ("Found not exactly one recipient but " + aRecipients.size ()); // retrieve recipient and decode it final RecipientInformation aRecipientInfo = aRecipients.iterator ().next (); final byte [] aDecryptedData = aRecipientInfo.getContent (new JceKeyTransEnvelopedRecipient (m_aPrivateKey).setProvider (PBCProvider.getProvider ())); AsicUtils.copyStream (new NonBlockingByteArrayInputStream (aDecryptedData), aOS); } catch (final CMSException e) { throw new IOException (e.getMessage (), e); } } else { m_aAsicReader.writeFile (aOS); } }
LOGGER.info ("Starting new output buffering!"); m_aBAOS = new NonBlockingByteArrayOutputStream (DEFAULT_BUFSIZE); m_aOS = m_aBAOS;
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
@Nonnull public IAsicWriter addEncrypted (final InputStream aIS, final String sFilename, final IMimeType aMimeType) throws IOException { try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) { AsicUtils.copyStream (aIS, aBAOS); final CMSEnvelopedDataGenerator aCMSEnvelopedDataGenerator = new CMSEnvelopedDataGenerator (); aCMSEnvelopedDataGenerator.addRecipientInfoGenerator (new JceKeyTransRecipientInfoGenerator (m_aCertificate).setProvider (PBCProvider.getProvider ())); final CMSEnvelopedData aData = aCMSEnvelopedDataGenerator.generate (new CMSProcessableByteArray (aBAOS.toByteArray ()), new JceCMSContentEncryptorBuilder (m_aCmsAlgorithm).setProvider (PBCProvider.getProvider ()) .build ()); m_aEntryNames.add (sFilename); return m_aAsicWriter.add (new NonBlockingByteArrayInputStream (aData.getEncoded ()), sFilename + ".p7m", aMimeType); } catch (final CMSException | CertificateEncodingException e) { throw new IOException (e.getMessage (), e); } }
try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream ()) try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream ())
public static void createHTMLResponse (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope, @Nonnull final UnifiedResponse aUnifiedResponse, @Nonnull final IHTMLProvider aHTMLProvider) { // Build the main HC tree final HCHtml aHtml = aHTMLProvider.createHTML (aRequestScope); // Add some ad comment :) aHtml.head () .metaElements () .add (new HCMeta ().setName (EStandardMetaElement.GENERATOR.getName ()) .setContent ("https://github.com/phax/ph-oton // phax // ASL 2.0")); // Convert HTML to String, including namespaces try ( final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 * CGlobal.BYTES_PER_KILOBYTE)) { final IMimeType aMimeType = getMimeType (aRequestScope); final IHCConversionSettings aCS = HCSettings.getConversionSettings (); HCRenderer.writeHtmlTo (aHtml, aCS, aBAOS); // Write to response aUnifiedResponse.setMimeType (aMimeType) .setCharset (aCS.getCharset ()) .setContent (HasInputStream.multiple (aBAOS::getAsInputStream)) .disableCaching (); } }
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ())
aMDNStream = new NonBlockingByteArrayOutputStream ();