LoggingServletInputStream (final byte [] content) { m_aIS = new NonBlockingByteArrayInputStream (content); }
public MockServletInputStream (@Nonnull final byte [] aContent) { this (new NonBlockingByteArrayInputStream (aContent)); }
@Nonnull public static StreamSource create (@Nonnull final byte [] aXML) { return create (new NonBlockingByteArrayInputStream (aXML)); }
@Nonnull public static StreamSource create (@Nonnull final byte [] aXML, @Nonnegative final int nOfs, @Nonnegative final int nLength) { return create (new NonBlockingByteArrayInputStream (aXML, nOfs, nLength)); }
@Nonnull public static InputSource create (@Nonnull final byte [] aXML) { return create (new NonBlockingByteArrayInputStream (aXML)); }
@Nonnull public static InputSource create (@Nonnull final byte [] aXML, @Nonnegative final int nOfs, @Nonnegative final int nLen) { return create (new NonBlockingByteArrayInputStream (aXML, nOfs, nLen)); }
/** * Write the passed object to a byte array and return the input stream on that * array. * * @param aObject * The object to be written. May not be <code>null</code>. * @return <code>null</code> if the passed domain object could not be * converted because of validation errors. * @since 9.1.8 */ @Nullable default NonBlockingByteArrayInputStream getAsInputStream (@Nonnull final JAXBTYPE aObject) { final byte [] aBytes = getAsBytes (aObject); return aBytes == null ? null : new NonBlockingByteArrayInputStream (aBytes); } }
@Nullable public static X509Certificate getEndpointCertificate (@Nullable final EndpointType aEndpoint) throws CertificateException { final byte [] aCertString = getEndpointCertificateString (aEndpoint); if (aCertString == null) return null; return (X509Certificate) CertificateHelper.getX509CertificateFactory () .generateCertificate (new NonBlockingByteArrayInputStream (aCertString)); }
@Nonnull private static NonBlockingByteArrayInputStream _getCachedInputStream (@Nonnull @WillClose final InputStream aIS) { return new NonBlockingByteArrayInputStream (StreamHelper.getAllBytes (aIS)); }
@Nullable public BufferedReader getReader () { if (m_aContent == null) return null; final InputStream aIS = new NonBlockingByteArrayInputStream (m_aContent); final Reader aReader = StreamHelper.createReader (aIS, getCharacterEncodingObjOrDefault ()); return new BufferedReader (aReader); }
public CachingTransformStreamSource (@Nonnull @WillClose final InputStream aIS, @Nullable final String sSystemID) { super (new NonBlockingByteArrayInputStream (StreamHelper.getAllBytes (aIS)), sSystemID); }
@Nullable public X509Certificate getEndpointCertificate (@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID, @Nonnull final IProcessIdentifier aProcessID, @Nonnull final ISMPTransportProfile aTransportProfile) throws SMPClientException, CertificateException { final byte [] aCertString = getEndpointCertificateString (aServiceGroupID, aDocumentTypeID, aProcessID, aTransportProfile); if (aCertString == null) return null; return (X509Certificate) CertificateHelper.getX509CertificateFactory () .generateCertificate (new NonBlockingByteArrayInputStream (aCertString)); }
@Nonnull protected static InputStream getHeaderStream (@Nonnull final IMessage aMsg, @Nonnull final Charset aCharset) { final StringBuilder aSB = new StringBuilder (); // write headers to the string buffer aSB.append ("Message Headers:").append (CHttp.EOL); aMsg.headers ().forEachHeaderLine (sHeaderLine -> aSB.append (sHeaderLine).append (CHttp.EOL)); aSB.append (CHttp.EOL); // write attributes to the string buffer aSB.append ("Attributes:").append (CHttp.EOL); for (final Map.Entry <String, String> attrEntry : aMsg.attrs ().entrySet ()) { aSB.append (attrEntry.getKey ()).append (": ").append (attrEntry.getValue ()).append (CHttp.EOL); } return new NonBlockingByteArrayInputStream (aSB.toString ().getBytes (aCharset)); } }
/** * Read a document from the specified byte array. The secure reading feature * has affect when using this method. * * @param aXML * The XML bytes to read. May not be <code>null</code>. * @return <code>null</code> in case reading fails. */ @Nullable default JAXBTYPE read (@Nonnull final byte [] aXML) { ValueEnforcer.notNull (aXML, "XML"); // Ensure to use InputStream for BOM handling return read (new NonBlockingByteArrayInputStream (aXML)); }
@Nonnull protected InputStream getMDNStream (@Nonnull final IMessageMDN aMdn) { final String sNewLine = ENewLineMode.DEFAULT.getText (); final StringBuilder aSB = new StringBuilder (); // write HTTP headers to the string buffer aSB.append ("MDN Headers:").append (sNewLine); // Should use ISO-8859-1 charset for HTTP headers aMdn.headers ().forEachHeaderLine (sHeaderLine -> aSB.append (sHeaderLine).append (sNewLine)); // Empty line aSB.append (sNewLine); // write attributes to the string buffer aSB.append ("MDN Attributes:").append (sNewLine); for (final Map.Entry <String, String> aEntry : aMdn.attrs ().entrySet ()) { aSB.append (aEntry.getKey ()).append (": ").append (aEntry.getValue ()).append (sNewLine); } // finally, write the MDN text aSB.append ("Text:").append (sNewLine).append (aMdn.getText ()); return new NonBlockingByteArrayInputStream (aSB.toString ().getBytes (getCharset ())); } }
/** * @return An {@link InputStream} that can be used to retrieve the contents of * the file. */ @Nonnull public InputStream getInputStream () { if (isInMemory ()) { _ensureCachedContentIsPresent (); return new NonBlockingByteArrayInputStream (m_aCachedContent); } return FileHelper.getInputStream (m_aDFOS.getFile ()); }
final IJson aJson = JsonReader.readFromStream (new NonBlockingByteArrayInputStream (aBytes)); if (aJson != null)
try (final InputStream aIS = new NonBlockingByteArrayInputStream (aResponseBytes))
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); } }
@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); } }