KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jcetaglib > tools > MacInputStream


1 package net.sourceforge.jcetaglib.tools;
2
3 import javax.crypto.Mac;
4 import java.io.FilterInputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.InputStream JavaDoc;
7
8 /**
9  * MacInputStream. As it reads in data it passes it though a MAC
10  */

11
12
13 public class MacInputStream extends FilterInputStream JavaDoc {
14     private Mac mac = null;
15
16     public MacInputStream(InputStream JavaDoc st,
17                           Mac mac) {
18         super(st);
19         this.mac = mac;
20     }
21
22     public int read()
23             throws IOException JavaDoc {
24         int n = in.read();
25         if (n > -1) {
26             mac.update((byte) n);
27         }
28
29         return (n);
30     }
31
32     public int read(byte[] b)
33             throws IOException JavaDoc {
34         int n = in.read(b);
35         if (n > -1) {
36             mac.update(b, 0, n);
37         }
38
39         return (n);
40     }
41
42     public int read(byte[] b,
43                     int o,
44                     int l)
45             throws IOException JavaDoc {
46         int n = in.read(b, o, l);
47         if (n > -1) {
48             mac.update(b, o, n);
49         }
50
51         return (n);
52     }
53 }
54
Popular Tags