01: package org.bouncycastle.sasn1;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05:
06: class ConstructedOctetStream extends InputStream {
07: private final Asn1InputStream _aIn;
08:
09: private boolean _first = true;
10: private InputStream _currentStream;
11:
12: ConstructedOctetStream(InputStream in) {
13: _aIn = new Asn1InputStream(in);
14: }
15:
16: public int read() throws IOException {
17: if (_first) {
18: Asn1OctetString s = (Asn1OctetString) _aIn.readObject();
19:
20: if (s == null) {
21: return -1;
22: }
23:
24: _first = false;
25: _currentStream = s.getOctetStream();
26: } else if (_currentStream == null) {
27: return -1;
28: }
29:
30: int b = _currentStream.read();
31:
32: if (b < 0) {
33: Asn1OctetString s = (Asn1OctetString) _aIn.readObject();
34:
35: if (s == null) {
36: _currentStream = null;
37:
38: return -1;
39: }
40:
41: _currentStream = s.getOctetStream();
42:
43: return _currentStream.read();
44: } else {
45: return b;
46: }
47: }
48: }
|