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); } }
@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; } }
/** * Returns the length of the data for this output stream as number of bytes, * assuming that the data has been retained in memory. If the data was written * to disk, this method returns <code>0</code>. * * @return The length of the data for this output stream, or <code>0</code> if * no such data is available. * @see #isInMemory() */ @Nonnegative public int getDataLength () { if (m_aMemoryOS != null) return m_aMemoryOS.size (); return 0; }
public void writeContentTo (final OutputStream aOS) throws IOException { if (!m_aDelegate.isCommitted () && m_aOS.m_aBAOS.isNotEmpty ()) m_aOS.m_aBAOS.writeTo (aOS); }
public void setContent (@Nonnull final NonBlockingByteArrayOutputStream aBAOS) { setContent (aBAOS.directGetBuffer (), 0, aBAOS.size ()); }
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) final byte [] aContent = aBAOS.toByteArray (); final String sContent = new String (aContent, StandardCharsets.ISO_8859_1); final String sigReference = CadesAsicManifest.extractAndVerify (sContent, m_aManifestVerifier); final String sContent = aBAOS.getAsString (StandardCharsets.ISO_8859_1); XadesAsicManifest.extractAndVerify (sContent, m_aManifestVerifier); _handleCadesSigning (m_aCurrentZipEntry.getName (), aBAOS.toByteArray (), true); m_aManifest = AsicReader.oasisManifest ().read (aBAOS.getAsInputStream ());
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); }
final NonBlockingByteArrayOutputStream aMDNStream = new NonBlockingByteArrayOutputStream (); try aIncomingDumper.dumpIncomingRequest (aMDN.headers ().getAllHeaderLines (), aMDNStream.toByteArray (), aMDN); LOGGER.trace ("Retrieved MDN stream data:\n" + aMDNStream.getAsString (StandardCharsets.ISO_8859_1)); aMDNStream.toByteArray ()); aMsg.getMDN ().setData (aPart);
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); } } }
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) else nHeaderSepIndex = 0; aBAOS.write (b); return aBAOS.getAsString (aCharsetToUse);
return null; try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (1024)) bFirst = false; else aBAOS.write ('&'); if (StringHelper.hasText (sValue)) aBAOS.write ('='); aURLCodec.encode (sValue.getBytes (aCharset), aBAOS); return new InputStreamEntity (aBAOS.getAsInputStream ());
try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream ()) CadesAsicManifest.extractAndVerify (aBAOS.getAsString (StandardCharsets.UTF_8), manifestVerifier); copyStream (aBAOS.getAsInputStream (), aAOS); final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (); copyStream (aAIS, aBAOS); aOasisManifest.addAll (new OasisManifest (aBAOS.getAsInputStream ()));
LOGGER.info ("Starting new output buffering!"); m_aBAOS = new NonBlockingByteArrayOutputStream (DEFAULT_BUFSIZE); m_aOS = m_aBAOS; doNotCompress ("_prepareToWrite buffered " + m_nContentLength); else if (nLength >= (m_aBAOS.getBufferSize () - m_aBAOS.size ())) doCompress ("_prepareToWrite buffered " + nLength); else
/** * 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); } }
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]]"); } }
try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream ()) try (final NonBlockingByteArrayOutputStream aData = new NonBlockingByteArrayOutputStream ()) aMdn.headers ().setContentLength (aData.size ());
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); } }
public byte [] getContentAsBytes () { return m_aOS.m_aBAOS.toByteArray (); }
@Override public void write (final int b) throws IOException { m_aBAOS.write (b); }
public final void doNotCompress (final String sDebugInfo) throws IOException { if (m_aCompressedOS != null) throw new IllegalStateException ("Compressed output stream is already assigned."); if (m_aOS == null || m_aBAOS != null) { m_bDoNotCompress = true; _debugLog (false, sDebugInfo); m_aOS = m_aHttpResponse.getOutputStream (); setContentLength (m_nContentLength); if (m_aBAOS != null) { // Copy all cached content m_aBAOS.writeTo (m_aOS); m_aBAOS = null; } } }