    001package org.apache.commons.ssl.asn1;
    002
    003import java.io.ByteArrayOutputStream;
    004import java.io.IOException;
    005import java.io.InputStream;
    006
    007public class BEROctetStringParser
    008    implements ASN1OctetStringParser {
    009    private ASN1ObjectParser _parser;
    010
    011    protected BEROctetStringParser(
    012        ASN1ObjectParser parser) {
    013        _parser = parser;
    014    }
    015
    016    public InputStream getOctetStream() {
    017        return new ConstructedOctetStream(_parser);
    018    }
    019
    020    public DERObject getDERObject() {
    021        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    022        InputStream in = this.getOctetStream();
    023        int ch;
    024
    025        try {
    026            while ((ch = in.read()) >= 0) {
    027                bOut.write(ch);
    028            }
    029        }
    030        catch (IOException e) {
    031            throw new IllegalStateException("IOException converting stream to byte array: " + e.getMessage());
    032        }
    033
    034        return new BERConstructedOctetString(bOut.toByteArray());
    035    }
    036}