/** * @deprecated use getContent(InputExpandedProvider) */ public CMSTypedStream getContent() throws CMSException { try { CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)_contentInfo.getContent(BERTags.SEQUENCE)); ContentInfoParser content = comData.getEncapContentInfo(); ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING); return new CMSTypedStream(content.getContentType().toString(), new InflaterInputStream(bytes.getOctetStream())); } catch (IOException e) { throw new CMSException("IOException reading compressed content.", e); } }
/** * Return a typed stream which will allow the reading of the compressed content in * expanded form. * * @param expanderProvider a provider of expander algorithm implementations. * @return a type stream which will yield the un-compressed content. * @throws CMSException if there is an exception parsing the CompressedData object. */ public CMSTypedStream getContent(InputExpanderProvider expanderProvider) throws CMSException { try { CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)_contentInfo.getContent(BERTags.SEQUENCE)); ContentInfoParser content = comData.getEncapContentInfo(); InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier()); ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING); return new CMSTypedStream(content.getContentType().getId(), expander.getInputStream(bytes.getOctetStream())); } catch (IOException e) { throw new CMSException("IOException reading compressed content.", e); } }
public void testNestedStructure() throws Exception { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); BERSequenceGenerator sGen = new BERSequenceGenerator(bOut); sGen.addObject(new DERObjectIdentifier(CMSObjectIdentifiers.compressedData.getId())); BERSequenceGenerator cGen = new BERSequenceGenerator(sGen.getRawOutputStream(), 0, true); cGen.addObject(new DERInteger(0)); // // AlgorithmIdentifier // DERSequenceGenerator algGen = new DERSequenceGenerator(cGen.getRawOutputStream()); algGen.addObject(new DERObjectIdentifier("1.2")); algGen.close(); // // Encapsulated ContentInfo // BERSequenceGenerator eiGen = new BERSequenceGenerator(cGen.getRawOutputStream()); eiGen.addObject(new DERObjectIdentifier("1.1")); BEROctetStringGenerator octGen = new BEROctetStringGenerator(eiGen.getRawOutputStream(), 0, true); // // output containing zeroes // OutputStream out = octGen.getOctetOutputStream(); out.write(new byte[] { 1, 2, 3, 4 }); out.write(new byte[4]); out.write(new byte[20]); out.close(); eiGen.close(); cGen.close(); sGen.close(); // // reading back // ASN1StreamParser aIn = new ASN1StreamParser(bOut.toByteArray()); ContentInfoParser cp = new ContentInfoParser((ASN1SequenceParser)aIn.readObject()); CompressedDataParser comData = new CompressedDataParser((ASN1SequenceParser)cp.getContent(BERTags.SEQUENCE)); ContentInfoParser content = comData.getEncapContentInfo(); ASN1OctetStringParser bytes = (ASN1OctetStringParser)content.getContent(BERTags.OCTET_STRING); InputStream in = bytes.getOctetStream(); int count = 0; while (in.read() >= 0) { count++; } assertEquals(28, count); }