From 2297be65c50d36916e6efc690ad297a149590e1f Mon Sep 17 00:00:00 2001 From: Abhiram555 <63419731+Sasuke449@users.noreply.github.com> Date: Thu, 19 Jan 2023 03:57:35 +0530 Subject: Fixed issue #81 (#82) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove the useless relocation in gradle * Implement the getMods command * Update src/main/java/de/torui/coflsky/commands/models/ModListData.java Co-authored-by: Äkwav <16632490+Ekwav@users.noreply.github.com> --- .../java/de/torui/coflsky/utils/FileUtils.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/main/java/de/torui/coflsky/utils/FileUtils.java (limited to 'src/main/java/de/torui/coflsky/utils') diff --git a/src/main/java/de/torui/coflsky/utils/FileUtils.java b/src/main/java/de/torui/coflsky/utils/FileUtils.java new file mode 100644 index 0000000..1541a75 --- /dev/null +++ b/src/main/java/de/torui/coflsky/utils/FileUtils.java @@ -0,0 +1,40 @@ +package de.torui.coflsky.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.security.MessageDigest; + +public class FileUtils { + + public static byte[] createChecksum(File file) throws Exception { + InputStream fis = new FileInputStream(file); + + byte[] buffer = new byte[1024]; + MessageDigest complete = MessageDigest.getInstance("MD5"); + int numRead; + + do { + numRead = fis.read(buffer); + if (numRead > 0) { + complete.update(buffer, 0, numRead); + } + } while (numRead != -1); + + fis.close(); + return complete.digest(); + } + + + public static String getMD5Checksum(File file) throws Exception { + byte[] b = createChecksum(file); + String result = ""; + + for (int i=0; i < b.length; i++) { + result += Integer.toString( ( b[i] & 0xff ) + 0x100, 16).substring( 1 ); + } + return result; + } + + +} -- cgit