01: package org.bouncycastle.crypto.io;
02:
03: import java.io.FilterInputStream;
04: import java.io.IOException;
05: import java.io.InputStream;
06:
07: import org.bouncycastle.crypto.Digest;
08:
09: public class DigestInputStream extends FilterInputStream {
10: protected Digest digest;
11:
12: public DigestInputStream(InputStream stream, Digest digest) {
13: super (stream);
14: this .digest = digest;
15: }
16:
17: public int read() throws IOException {
18: int b = in.read();
19:
20: if (b >= 0) {
21: digest.update((byte) b);
22: }
23: return b;
24: }
25:
26: public int read(byte[] b, int off, int len) throws IOException {
27: int n = in.read(b, off, len);
28: if (n > 0) {
29: digest.update(b, off, n);
30: }
31: return n;
32: }
33:
34: public Digest getDigest() {
35: return digest;
36: }
37: }
|