diff --git a/pom.xml b/pom.xml index 211394e..2c97dd1 100644 --- a/pom.xml +++ b/pom.xml @@ -29,8 +29,13 @@ - 17 - 17 + UTF-8 + UTF-8 + 17 + ${java.version} + ${java.version} + target + \ No newline at end of file diff --git a/src/main/java/org/rrajesh1979/demo/CheckSum.java b/src/main/java/org/rrajesh1979/demo/CheckSum.java new file mode 100644 index 0000000..c36cf0e --- /dev/null +++ b/src/main/java/org/rrajesh1979/demo/CheckSum.java @@ -0,0 +1,33 @@ +package org.rrajesh1979.demo; + +import java.io.File; +import java.math.BigInteger; +import java.io.IOException; +import java.nio.file.Files; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +public class CheckSum { + static String algorithm = "MD5"; + + public static void main(String[] args) { + String fileName = ""; + if (args.length > 0) { + fileName = args[0]; + } + try { + byte[] checkSum = getCheckSum(fileName); + System.out.printf("%0" + (checkSum.length*2) + "x%n", new BigInteger(1, checkSum)); + } catch (IOException | NoSuchAlgorithmException e) { + e.printStackTrace(); + } + + } + + public static byte[] getCheckSum(String fileName) throws IOException, NoSuchAlgorithmException { + File file = new File(fileName); + byte[] fileContents = Files.readAllBytes(file.toPath()); + byte[] digest = MessageDigest.getInstance(algorithm).digest(fileContents); + return digest; + } +} diff --git a/src/main/resources/testdata/TestFile-1.txt b/src/main/resources/testdata/TestFile-1.txt new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/src/main/resources/testdata/TestFile-1.txt @@ -0,0 +1 @@ +Hello World! \ No newline at end of file