if (file.length() < SHA256_FILE_USE_SHELL_THRESHHOLD) return sha256_file_java(file);
result = exec(new CommandLine("sha256sum").addArgument(abs(file), false));
result = exec(shaCommand().addArgument(abs(file), false));
if (result.isZeroExitStatus()) return split(result.getStdout(), " ").get(0);
} catch (Exception e) {
@@ -80,6 +81,14 @@ public class ShaUtil {
return die("sha256sum_file: sha256sum "+abs(file)+" exited with status "+result.getExitStatus()+", stderr="+result.getStderr()+", exception="+result.getExceptionString());
}
private static CommandLine shaCommand() {
if (IS_OS_MAC) {
return new CommandLine("shasum").addArgument("-a").addArgument("256");
} else {
return new CommandLine("sha256sum");
}
}
public static String sha256_file_java(File file) {
try {
@Cleanup final InputStream input = new FileInputStream(file);