Created
November 20, 2019 11:06
-
-
Save mattjtodd/1d6f242c57df4a6e15370388bf0fef0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.common.hash.Hashing; | |
import com.google.common.hash.HashingInputStream; | |
import java.io.FileInputStream; | |
public class App { | |
public static void main(String[] args) throws Exception { | |
// read a file, create a hashing stream for SHA-256 | |
try (HashingInputStream hashingInputStream = new HashingInputStream(Hashing.sha256(), new FileInputStream("/Users/matttodd/dev/personal/file-digest/hello2.txt"))) { | |
// read the stream fully to calculate hash | |
while (hashingInputStream.read() != -1); | |
System.out.println(hashingInputStream.hash()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment