Home | History | Annotate | Download | only in io
      1 package org.bouncycastle.crypto.io;
      2 
      3 import java.io.FilterInputStream;
      4 import java.io.IOException;
      5 import java.io.InputStream;
      6 
      7 import org.bouncycastle.crypto.Digest;
      8 
      9 public class DigestInputStream
     10     extends FilterInputStream
     11 {
     12     protected Digest digest;
     13 
     14     public DigestInputStream(
     15         InputStream stream,
     16         Digest      digest)
     17     {
     18         super(stream);
     19         this.digest = digest;
     20     }
     21 
     22     public int read()
     23         throws IOException
     24     {
     25         int b = in.read();
     26 
     27         if (b >= 0)
     28         {
     29             digest.update((byte)b);
     30         }
     31         return b;
     32     }
     33 
     34     public int read(
     35         byte[] b,
     36         int off,
     37         int len)
     38         throws IOException
     39     {
     40         int n = in.read(b, off, len);
     41         if (n > 0)
     42         {
     43             digest.update(b, off, n);
     44         }
     45         return n;
     46     }
     47 
     48     public Digest getDigest()
     49     {
     50         return digest;
     51     }
     52 }
     53