List of usage examples for java.security DigestInputStream on
boolean on
To view the source code for java.security DigestInputStream on.
Click Source Link
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fis = new FileInputStream("test"); MessageDigest md = MessageDigest.getInstance("SHA"); DigestInputStream dis = new DigestInputStream(fis, md); ObjectInputStream ois = new ObjectInputStream(dis); Object o = ois.readObject();//from w w w .jav a 2 s . c om if (!(o instanceof String)) { System.out.println("Unexpected data in file"); System.exit(-1); } String data = (String) o; System.out.println("Got message " + data); dis.on(false); o = ois.readObject(); if (!(o instanceof byte[])) { System.out.println("Unexpected data in file"); System.exit(-1); } byte origDigest[] = (byte[]) o; System.out.println(MessageDigest.isEqual(md.digest(), origDigest)); }