while ((len = inOctets.read(inBuffer, 0, outBuffer.length)) >= 0)
while ((len = inOctets.read(inBuffer, 0, inBuffer.length)) >= 0)
    public static OutputStream replaceSigners(        InputStream             original,        SignerInformationStore  signerInformationStore,        OutputStream            out)        throws CMSException, IOException    {        ASN1StreamParser in = new ASN1StreamParser(original, CMSUtils.getMaximumMemory());        ContentInfoParser contentInfo = new ContentInfoParser((ASN1SequenceParser)in.readObject());        SignedDataParser signedData = SignedDataParser.getInstance(contentInfo.getContent(DERTags.SEQUENCE));        BERSequenceGenerator sGen = new BERSequenceGenerator(out);        sGen.addObject(CMSObjectIdentifiers.signedData);        BERSequenceGenerator sigGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true);        // version number        sigGen.addObject(signedData.getVersion());        // digests        signedData.getDigestAlgorithms().getDERObject();  // skip old ones        ASN1EncodableVector digestAlgs = new ASN1EncodableVector();        for (Iterator it = signerInformationStore.getSigners().iterator(); it.hasNext();)        {            SignerInformation        signer = (SignerInformation)it.next();            AlgorithmIdentifier     digAlgId;            digAlgId = makeAlgId(signer.getDigestAlgOID(), signer.getDigestAlgParams());            digestAlgs.add(digAlgId);        }        sigGen.getRawOutputStream().write(new DERSet(digestAlgs).getEncoded());        // encap content info        ContentInfoParser encapContentInfo = signedData.getEncapContentInfo();        BERSequenceGenerator eiGen = new BERSequenceGenerator(sigGen.getRawOutputStream());        eiGen.addObject(encapContentInfo.getContentType());        ASN1OctetStringParser octs = (ASN1OctetStringParser)encapContentInfo.getContent(DERTags.OCTET_STRING);        if (octs != null)        {            BEROctetStringGenerator octGen = new BEROctetStringGenerator(eiGen.getRawOutputStream(), 0, true);            byte[]                  inBuffer = new byte[4096];            byte[]                  outBuffer = new byte[4096];            InputStream             inOctets = octs.getOctetStream();            OutputStream            outOctets = octGen.getOctetOutputStream(outBuffer);            int len;            while ((len = inOctets.read(inBuffer, 0, outBuffer.length)) >= 0)            {                outOctets.write(inBuffer, 0, len);            }            outOctets.close();        }        eiGen.close();        ASN1SetParser set = signedData.getCertificates();        if (set instanceof BERSetParser)        {            sigGen.getRawOutputStream().write(new BERTaggedObject(false, 0, set.getDERObject()).getEncoded());        }        else if (set != null)        {            sigGen.getRawOutputStream().write(new DERTaggedObject(false, 0, set.getDERObject()).getEncoded());        }        set = signedData.getCrls();        if (set instanceof BERSet)        {            sigGen.getRawOutputStream().write(new BERTaggedObject(false, 1, set.getDERObject()).getEncoded());        }        else if (set != null)        {            sigGen.getRawOutputStream().write(new DERTaggedObject(false, 1, set.getDERObject()).getEncoded());        }        ASN1EncodableVector signerInfos = new ASN1EncodableVector();        for (Iterator it = signerInformationStore.getSigners().iterator(); it.hasNext();)        {            SignerInformation        signer = (SignerInformation)it.next();            signerInfos.add(signer.toSignerInfo());        }        sigGen.getRawOutputStream().write(new DERSet(signerInfos).getEncoded());        sigGen.close();        sGen.close();        return out;    }