1package org.bouncycastle.crypto.io;
2
3import java.io.FilterOutputStream;
4import java.io.IOException;
5import java.io.OutputStream;
6
7import org.bouncycastle.crypto.Digest;
8
9public class DigestOutputStream
10    extends FilterOutputStream
11{
12    protected Digest digest;
13
14    public DigestOutputStream(
15        OutputStream    stream,
16        Digest          digest)
17    {
18        super(stream);
19        this.digest = digest;
20    }
21
22    public void write(int b)
23        throws IOException
24    {
25        digest.update((byte)b);
26        out.write(b);
27    }
28
29    public void write(
30        byte[] b,
31        int off,
32        int len)
33        throws IOException
34    {
35        digest.update(b, off, len);
36        out.write(b, off, len);
37    }
38
39    public Digest getDigest()
40    {
41        return digest;
42    }
43}
44