1 24 package com.Ostermiller.util; 25 26 import java.io.*; 27 28 52 public class MD5InputStream extends FilterInputStream { 53 56 private MD5 md5; 57 58 62 public MD5InputStream (InputStream in) { 63 super(in); 64 md5 = new MD5(); 65 } 66 67 81 public int read() throws IOException { 82 int c = in.read(); 83 if (c == -1) { 84 return -1; 85 } else { 86 md5.update((byte)(c & 0xff)); 87 return c; 88 } 89 } 90 91 102 public int read(byte[] bytes, int offset, int length) throws IOException { 103 int r; 104 if ((r = in.read(bytes, offset, length)) == -1) { 105 return r; 106 } else { 107 md5.update(bytes, offset, r); 108 return r; 109 } 110 } 111 112 119 public byte[] getHash(){ 120 return md5.getHash(); 121 } 122 123 130 public String getHashString(){ 131 return md5.getHashString(); 132 } 133 } 134 | Popular Tags |