import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.DigestInputStream;
import java.security.DigestOutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HelloDigestInputAndOutputStreams {
	
	private static final String FILENAME = "md5.txt";
	public static void main(String...args) {
		System.out.println("Hello Digest Input and Output Streams");
		
		try (DigestOutputStream dos = new DigestOutputStream(
			new FileOutputStream(FILENAME),
			MessageDigest.getInstance("md5"))) {
						
			for (int i = 0; i < 100; i++)  {
				dos.write("Hello World\n".getBytes());
			}
			
			MessageDigest md = dos.getMessageDigest();
			String digestStr = new BigInteger(1, md.digest()).toString(16);
			System.out.printf("Message Digest after writing: %s\n", digestStr);
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
				
		try (DigestInputStream dis = new DigestInputStream(
			new FileInputStream(FILENAME),
			MessageDigest.getInstance("md5"))) {
			
			while (dis.read() != -1) {
				// null-op
			}
			
			MessageDigest md = dis.getMessageDigest();
			String digestStr = new BigInteger(1, md.digest()).toString(16);
			System.out.printf("Message Digest after reading: %s\n", digestStr);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

@@ -366,19 +366,21 @@
 reams %7B%0A
-%09%0A%09
+%0A    
 private 
@@ -421,17 +421,21 @@
 5.txt%22;%0A
-%09
+%0A    
 public s
@@ -463,16 +463,17 @@
 g...
+ 
 args) %7B%0A
 %09%09Sy
@@ -468,18 +468,24 @@
 args) %7B%0A
-%09%09
+        
 System.o
@@ -537,21 +537,25 @@
 eams%22);%0A
-%09%09%0A%09%09
+%0A        
 try (Dig
@@ -591,36 +591,32 @@
 estOutputStream(
-%0A%09%09%09
 new FileOutputSt
@@ -623,35 +623,48 @@
 ream(FILENAME),%0A
-%09%09%09
+                
 MessageDigest.ge
@@ -688,18 +688,21 @@
 ) %7B%0A
-%09%09%09%09%09%09%0A%09%09%09
+%0A            
 for 
@@ -730,16 +730,27 @@
 i++)
- 
  %7B%0A
-%09%09%09%09
+                
 dos.
@@ -784,28 +784,43 @@
 tes());%0A
-%09%09%09%7D%0A%09%09%09%0A%09%09%09
+            %7D%0A%0A            
 MessageD
@@ -846,35 +846,44 @@
 essageDigest();%0A
-%09%09%09
+            
 String digestStr
@@ -922,35 +922,44 @@
 ).toString(16);%0A
-%09%09%09
+            
 System.out.print
@@ -1010,22 +1010,25 @@
 stStr);%0A
-%09%09%09%0A%09%09
+%0A        
 %7D catch 
@@ -1047,35 +1047,44 @@
 dException e) %7B%0A
-%09%09%09
+            
 e.printStackTrac
@@ -1080,34 +1080,40 @@
 ntStackTrace();%0A
-%09%09
+        
 %7D catch (NoSuchA
@@ -1127,35 +1127,44 @@
 mException e) %7B%0A
-%09%09%09
+            
 e.printStackTrac
@@ -1160,34 +1160,40 @@
 ntStackTrace();%0A
-%09%09
+        
 %7D catch (IOExcep
@@ -1194,35 +1194,44 @@
 OException e) %7B%0A
-%09%09%09
+            
 e.printStackTrac
@@ -1239,19 +1239,27 @@
 ();%0A
-%09%09%7D%0A%09%09%09%09%0A%09%09
+        %7D%0A%0A        
 try 
@@ -1305,20 +1305,16 @@
 tStream(
-%0A%09%09%09
 new File
@@ -1336,19 +1336,32 @@
 ENAME),%0A
-%09%09%09
+                
 MessageD
@@ -1389,23 +1389,29 @@
 5%22))) %7B%0A
-%09%09%09%0A%09%09%09
+%0A            
 while (d
@@ -1433,35 +1433,62 @@
 ) %7B%0A
-%09%09%09%09// null-op%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09
+                // null-op%0A            %7D%0A%0A            
 Mess
@@ -1526,19 +1526,28 @@
 gest();%0A
-%09%09%09
+            
 String d
@@ -1602,19 +1602,28 @@
 ng(16);%0A
-%09%09%09
+            
 System.o
@@ -1683,18 +1683,24 @@
 tStr);%0A%0A
-%09%09
+        
 %7D catch 
@@ -1719,35 +1719,44 @@
 dException e) %7B%0A
-%09%09%09
+            
 e.printStackTrac
@@ -1752,34 +1752,40 @@
 ntStackTrace();%0A
-%09%09
+        
 %7D catch (NoSuchA
@@ -1799,35 +1799,44 @@
 mException e) %7B%0A
-%09%09%09
+            
 e.printStackTrac
@@ -1840,18 +1840,24 @@
 race();%0A
-%09%09
+        
 %7D catch 
@@ -1878,11 +1878,20 @@
 ) %7B%0A
-%09%09%09
+            
 e.pr
@@ -1911,13 +1911,22 @@
 ();%0A
-%09%09%7D%0A%09
+        %7D%0A    
 %7D%0A%7D%0A

Update HelloDigestInputAndOutputStreams.java