KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sourceforge.jcetaglib.tools;
2
3 import java.io.FilterOutputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.OutputStream JavaDoc;
6 import java.security.Signature JavaDoc;
7 import java.security.SignatureException JavaDoc;
8
9
10 /**
11  * Signature output stream is a stream wrapper that
12  * passes data though a Signature object before passing it on.
13  */

14
15
16 public class SignatureOutputStream
17         extends FilterOutputStream JavaDoc {
18     private Signature JavaDoc sig = null;
19
20     public SignatureOutputStream(OutputStream JavaDoc out,
21                                  Signature JavaDoc sig) {
22         super(out);
23         this.sig = sig;
24     }
25
26     public void write(int b)
27             throws IOException JavaDoc {
28         try {
29             sig.update((byte) b);
30         } catch (SignatureException JavaDoc s_ex) {
31             throw new IOException JavaDoc(s_ex.getMessage());
32         }
33         out.write(b);
34     }
35
36     public void write(byte[] b)
37             throws IOException JavaDoc {
38         try {
39             sig.update(b);
40         } catch (SignatureException JavaDoc s_ex) {
41             throw new IOException JavaDoc(s_ex.getMessage());
42         }
43
44         out.write(b);
45     }
46
47     public void write(byte[] b,
48                       int o,
49                       int l)
50             throws IOException JavaDoc {
51         try {
52             sig.update(b, o, l);
53         } catch (SignatureException JavaDoc s_ex) {
54             throw(new IOException JavaDoc(s_ex.getMessage()));
55         }
56
57         out.write(b, o, l);
58     }
59 }
60
61
Popular Tags