KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sourceforge.jcetaglib.tools;
2
3 import javax.crypto.Mac;
4 import java.io.FilterOutputStream JavaDoc;
5 import java.io.IOException JavaDoc;
6 import java.io.OutputStream JavaDoc;
7
8 /**
9  * MacOutputStream. As data it writen it passes it updates a MAC.
10  */

11
12 public class MacOutputStream extends FilterOutputStream JavaDoc {
13     private Mac mac = null;
14
15     public MacOutputStream(OutputStream JavaDoc out,
16                            Mac mac) {
17         super(out);
18         this.mac = mac;
19     }
20
21     public void write(int b)
22             throws IOException JavaDoc {
23         mac.update((byte) b);
24         out.write(b);
25     }
26
27     public void write(byte[] b)
28             throws IOException JavaDoc {
29         mac.update(b);
30         out.write(b);
31     }
32
33     public void write(byte[] b,
34                       int o,
35                       int l)
36             throws IOException JavaDoc {
37         mac.update(b, o, l);
38         out.write(b, o, l);
39     }
40 }
41
Popular Tags