1 package net.sourceforge.jcetaglib.tools; 2 3 import java.io.FilterInputStream ; 4 import java.io.IOException ; 5 import java.io.InputStream ; 6 import java.security.Signature ; 7 import java.security.SignatureException ; 8 9 12 13 14 public class SignatureInputStream extends FilterInputStream { 15 private Signature sig = null; 16 17 public SignatureInputStream(InputStream st, 18 Signature sig) { 19 super(st); 20 this.sig = sig; 21 } 22 23 public int read() 24 throws IOException { 25 int n = in.read(); 26 if (n > -1) { 27 try { 28 sig.update((byte) n); 29 } catch (SignatureException s_ex) { 30 throw(new IOException (s_ex.getMessage())); 31 } 32 } 33 34 return (n); 35 } 36 37 public int read(byte[] b) 38 throws IOException { 39 int n = in.read(b); 40 if (n > -1) { 41 try { 42 sig.update(b, 0, n); 43 } catch (SignatureException s_ex) { 44 throw new IOException (s_ex.getMessage()); 45 } 46 } 47 48 return (n); 49 } 50 51 public int read(byte[] b, 52 int o, 53 int l) 54 throws IOException { 55 int n = in.read(b, o, l); 56 if (n > -1) { 57 try { 58 sig.update(b, o, n); 59 } catch (SignatureException s_ex) { 60 throw(new IOException (s_ex.getMessage())); 61 } 62 } 63 64 return (n); 65 } 66 } 67 | Popular Tags |