Skip to content

Instantly share code, notes, and snippets.

@mattjtodd
Created November 20, 2019 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattjtodd/1d6f242c57df4a6e15370388bf0fef0b to your computer and use it in GitHub Desktop.
Save mattjtodd/1d6f242c57df4a6e15370388bf0fef0b to your computer and use it in GitHub Desktop.
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