01: package org.bouncycastle.cms;
02:
03: import java.io.ByteArrayInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06: import java.util.zip.InflaterInputStream;
07:
08: import org.bouncycastle.asn1.cms.CompressedDataParser;
09: import org.bouncycastle.asn1.cms.ContentInfoParser;
10: import org.bouncycastle.asn1.ASN1OctetStringParser;
11: import org.bouncycastle.asn1.ASN1SequenceParser;
12: import org.bouncycastle.asn1.DERTags;
13:
14: /**
15: * Class for reading a CMS Compressed Data stream.
16: * <pre>
17: * CMSCompressedDataParser cp = new CMSCompressedDataParser(inputStream);
18: *
19: * process(cp.getContent().getContentStream());
20: * </pre>
21: * Note: this class does not introduce buffering - if you are processing large files you should create
22: * the parser with:
23: * <pre>
24: * CMSCompressedDataParser ep = new CMSCompressedDataParser(new BufferedInputStream(inputStream, bufSize));
25: * </pre>
26: * where bufSize is a suitably large buffer size.
27: */
28: public class CMSCompressedDataParser extends CMSContentInfoParser {
29: public CMSCompressedDataParser(byte[] compressedData)
30: throws CMSException {
31: this (new ByteArrayInputStream(compressedData));
32: }
33:
34: public CMSCompressedDataParser(InputStream compressedData)
35: throws CMSException {
36: super (compressedData);
37: }
38:
39: public CMSTypedStream getContent() throws CMSException {
40: try {
41: CompressedDataParser comData = new CompressedDataParser(
42: (ASN1SequenceParser) _contentInfo
43: .getContent(DERTags.SEQUENCE));
44: ContentInfoParser content = comData.getEncapContentInfo();
45:
46: ASN1OctetStringParser bytes = (ASN1OctetStringParser) content
47: .getContent(DERTags.OCTET_STRING);
48:
49: return new CMSTypedStream(content.getContentType()
50: .toString(), new InflaterInputStream(bytes
51: .getOctetStream()));
52: } catch (IOException e) {
53: throw new CMSException(
54: "IOException reading compressed content.", e);
55: }
56: }
57: }
|