FileUtils { public static String getFileChecksumSHA256(final File artifactFile) throws IOException { MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { throw new IOException(e); } try (final FileInputStream fis = new FileInputStream(artifactFile)) { final byte[] byteArray = new byte[1024]; int bytesCount = 0; while ((bytesCount = fis.read(byteArray)) != -1) { digest.update(byteArray, 0, bytesCount); } } final byte[] bytes = digest.digest(); final StringBuilder sb = new StringBuilder(); for (int counter = 0; counter < bytes.length; counter++) { sb.append(Integer.toString((bytes[counter] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } private  FileUtils(); static void serialize(final File folder, final String content, final String fileName); static String read(final File file); static Long getSize(final File file); static void touch(final File folder , final String fileName); static String getFileChecksumSHA256(final File artifactFile);  }
@Test public void getFileChecksumSHA256Test() throws IOException { String sha256 = "687e8de2545679203124ebe3287a3724a2f7e40a8132ea65521c0e03637ea68d"; ClassLoader classLoader = getClass().getClassLoader(); File jarFile = new File(classLoader.getResource("sample-jar/sample-file").getFile()); String generatedSHA256 = FileUtils.getFileChecksumSHA256(jarFile); assertNotNull(generatedSHA256); assertEquals(sha256, generatedSHA256); }