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:
parent
647e23adc5
commit
b4b5a766f8
4 changed files with 44 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
|||
# 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
|
||||
|
||||
|
@ -24,7 +24,7 @@ Usage: sherly -f inputfolder1 inputfolder2 inputfolder3 [options]...
|
|||
## Build
|
||||
|
||||
```bash
|
||||
mvn package
|
||||
mvn package assembly:single
|
||||
```
|
||||
|
||||
## Supported Platforms
|
||||
|
|
45
pom.xml
45
pom.xml
|
@ -20,6 +20,11 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -40,8 +45,27 @@
|
|||
<version>3.8.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<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>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
|
@ -54,23 +78,6 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</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>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
|
|
@ -151,10 +151,10 @@ public class App {
|
|||
for (String checksum: fileMap.keySet()) {
|
||||
|
||||
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 {
|
||||
System.out.println(checksum +" --> " + fileMap.get(checksum));
|
||||
System.out.println(checksum +"\t--> " + fileMap.get(checksum));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ package net.chaoticbyte.xxsherly;
|
|||
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.Checksum;
|
||||
import org.apache.commons.codec.digest.XXHash32;
|
||||
|
||||
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)
|
||||
private String getChecksum (File file) throws IOException {
|
||||
MessageDigest messageDigest = null;
|
||||
|
||||
try {
|
||||
messageDigest = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
String digest = "";
|
||||
|
||||
// Calculate xxHash32 and add it's hexadecimal presentation to the digest
|
||||
|
||||
Checksum xxHash = new XXHash32();
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
|
||||
byte[] dataBytes = new byte[1024];
|
||||
int unread = 0;
|
||||
while ((unread = inputStream.read(dataBytes)) != -1) {
|
||||
messageDigest.update(dataBytes, 0, unread);
|
||||
xxHash.update(dataBytes, 0, unread);
|
||||
}
|
||||
|
||||
inputStream.close();
|
||||
digest += Long.toHexString(xxHash.getValue());
|
||||
|
||||
// get digest & create hexadecimal represenation
|
||||
byte[] digestBytes = messageDigest.digest();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (byte digestByte : digestBytes) {
|
||||
stringBuilder.append(Integer.toString((digestByte & 0xff) + 0x100, 16).substring(1));
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
// Add File length to the digest
|
||||
|
||||
digest += Long.toHexString(file.length());
|
||||
|
||||
// return result
|
||||
return digest;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue