// 
// Decompiled by Procyon v0.6.0
// 

package org.bouncycastle.asn1;

import org.bouncycastle.util.io.Streams;
import java.io.IOException;
import java.io.InputStream;

@Deprecated
public class BERBitStringParser implements ASN1BitStringParser
{
    private ASN1StreamParser _parser;
    private ConstructedBitStream _bitStream;
    
    BERBitStringParser(final ASN1StreamParser parser) {
        this._parser = parser;
    }
    
    @Override
    public InputStream getOctetStream() throws IOException {
        return this._bitStream = new ConstructedBitStream(this._parser, true);
    }
    
    @Override
    public InputStream getBitStream() throws IOException {
        return this._bitStream = new ConstructedBitStream(this._parser, false);
    }
    
    @Override
    public int getPadBits() {
        return this._bitStream.getPadBits();
    }
    
    @Override
    public ASN1Primitive getLoadedObject() throws IOException {
        return parse(this._parser);
    }
    
    @Override
    public ASN1Primitive toASN1Primitive() {
        try {
            return this.getLoadedObject();
        }
        catch (final IOException ex) {
            throw new ASN1ParsingException("IOException converting stream to byte array: " + ex.getMessage(), ex);
        }
    }
    
    static BERBitString parse(final ASN1StreamParser asn1StreamParser) throws IOException {
        final ConstructedBitStream constructedBitStream = new ConstructedBitStream(asn1StreamParser, false);
        return new BERBitString(Streams.readAll(constructedBitStream), constructedBitStream.getPadBits());
    }
}
