Switched to xxHash32 + file size for the calculation of checksums, removed unnecessary maven plugins, configured maven to build jars with dependencies

This commit is contained in:
Julian Müller (ChaoticByte) 2023-05-05 22:43:53 +02:00
parent 647e23adc5
commit b4b5a766f8
4 changed files with 44 additions and 41 deletions

View file

@ -1,6 +1,6 @@
# xxSherly # xxSherly
A fork of [Sherly](https://github.com/BlyDoesCoding/Sherly), (not yet) using [xxHash](https://github.com/Cyan4973/xxHash). A fork of [Sherly](https://github.com/BlyDoesCoding/Sherly), using [xxHash](https://github.com/Cyan4973/xxHash).
## Introduction ## Introduction
@ -24,7 +24,7 @@ Usage: sherly -f inputfolder1 inputfolder2 inputfolder3 [options]...
## Build ## Build
```bash ```bash
mvn package mvn package assembly:single
``` ```
## Supported Platforms ## Supported Platforms

45
pom.xml
View file

@ -20,6 +20,11 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.15</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -40,8 +45,27 @@
<version>3.8.0</version> <version>3.8.0</version>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-assembly-plugin</artifactId>
<version>2.22.1</version> <version>3.5.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>net.chaoticbyte.xxsherly.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
@ -54,23 +78,6 @@
</archive> </archive>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>

View file

@ -151,10 +151,10 @@ public class App {
for (String checksum: fileMap.keySet()) { for (String checksum: fileMap.keySet()) {
if (doTheColorThingy) { if (doTheColorThingy) {
System.out.println(ConsoleColors.BLUE_BOLD + checksum + ConsoleColors.CYAN_BOLD + " --> " + ConsoleColors.GREEN_BOLD + fileMap.get(checksum) + ConsoleColors.RESET); System.out.println(ConsoleColors.BLUE_BOLD + checksum + ConsoleColors.CYAN_BOLD + "\t--> " + ConsoleColors.GREEN_BOLD + fileMap.get(checksum) + ConsoleColors.RESET);
} else { } else {
System.out.println(checksum +" --> " + fileMap.get(checksum)); System.out.println(checksum +"\t--> " + fileMap.get(checksum));
} }
} }

View file

@ -2,10 +2,10 @@ package net.chaoticbyte.xxsherly;
import java.io.*; import java.io.*;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.zip.Checksum;
import org.apache.commons.codec.digest.XXHash32;
public class ThreadedCompare extends Thread { public class ThreadedCompare extends Thread {
@ -40,30 +40,26 @@ public class ThreadedCompare extends Thread {
//this is used to get the MD5 String of one of the files (one of them is just fine since they both have the same value) //this is used to get the MD5 String of one of the files (one of them is just fine since they both have the same value)
private String getChecksum (File file) throws IOException { private String getChecksum (File file) throws IOException {
MessageDigest messageDigest = null;
try { String digest = "";
messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
// Calculate xxHash32 and add it's hexadecimal presentation to the digest
Checksum xxHash = new XXHash32();
FileInputStream inputStream = new FileInputStream(file); FileInputStream inputStream = new FileInputStream(file);
byte[] dataBytes = new byte[1024]; byte[] dataBytes = new byte[1024];
int unread = 0; int unread = 0;
while ((unread = inputStream.read(dataBytes)) != -1) { while ((unread = inputStream.read(dataBytes)) != -1) {
messageDigest.update(dataBytes, 0, unread); xxHash.update(dataBytes, 0, unread);
} }
inputStream.close(); inputStream.close();
digest += Long.toHexString(xxHash.getValue());
// get digest & create hexadecimal represenation // Add File length to the digest
byte[] digestBytes = messageDigest.digest();
StringBuilder stringBuilder = new StringBuilder(); digest += Long.toHexString(file.length());
for (byte digestByte : digestBytes) {
stringBuilder.append(Integer.toString((digestByte & 0xff) + 0x100, 16).substring(1)); // return result
} return digest;
return stringBuilder.toString();
} }
} }