01: package org.bouncycastle.asn1;
02:
03: import java.io.InputStream;
04: import java.io.ByteArrayOutputStream;
05: import java.io.IOException;
06:
07: public class BEROctetStringParser implements ASN1OctetStringParser {
08: private ASN1ObjectParser _parser;
09:
10: protected BEROctetStringParser(ASN1ObjectParser parser) {
11: _parser = parser;
12: }
13:
14: public InputStream getOctetStream() {
15: return new ConstructedOctetStream(_parser);
16: }
17:
18: public DERObject getDERObject() {
19: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
20: InputStream in = this .getOctetStream();
21: int ch;
22:
23: try {
24: while ((ch = in.read()) >= 0) {
25: bOut.write(ch);
26: }
27: } catch (IOException e) {
28: throw new IllegalStateException(
29: "IOException converting stream to byte array: "
30: + e.getMessage());
31: }
32:
33: return new BERConstructedOctetString(bOut.toByteArray());
34: }
35: }
|