checkDataIntegrity
git-svn-id: svn://home0/checkDataIntegrity@2416 71dcc7fd-b1f2-4e5d-bb8e-274146e81173
This commit is contained in:
70
src/checkDataIntegrity/Main.java
Normal file
70
src/checkDataIntegrity/Main.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package checkDataIntegrity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(final String[] args) throws IOException {
|
||||
if (args.length < 2) {
|
||||
System.err.println("Usage: checkDataIntegrity.java <Path0> <Path1>");
|
||||
return;
|
||||
}
|
||||
final String path0 = args[0];
|
||||
final String path1 = args[1];
|
||||
System.out.println("Path0: " + path0);
|
||||
System.out.println("Path1: " + path1);
|
||||
|
||||
final long start = System.currentTimeMillis();
|
||||
final AtomicLong count = new AtomicLong();
|
||||
final AtomicLong countErr = new AtomicLong();
|
||||
final ThreadLocal<byte[]> bufs0 = ThreadLocal.withInitial(() -> new byte[4096]);
|
||||
final ThreadLocal<byte[]> bufs1 = ThreadLocal.withInitial(() -> new byte[4096]);
|
||||
|
||||
try (Stream<Path> walk = Files.walk(Path.of(path0))) {
|
||||
walk
|
||||
// .parallel()
|
||||
.filter(Files::isRegularFile)
|
||||
.forEach(p0 -> {
|
||||
count.incrementAndGet();
|
||||
|
||||
final String rel = p0.toString().substring(path0.length());
|
||||
final Path p1 = Path.of(path1 + rel);
|
||||
|
||||
final byte[] buf0 = bufs0.get();
|
||||
final byte[] buf1 = bufs1.get();
|
||||
try (InputStream inputStream0 = Files.newInputStream(p0); InputStream inputStream1 = Files.newInputStream(p1);) {
|
||||
final int len0 = inputStream0.read(buf0);
|
||||
final int len1 = inputStream1.read(buf1);
|
||||
if (len0 != len1) {
|
||||
System.out.println(rel + ": Length mismatch");
|
||||
countErr.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
if (len0 == -1) {
|
||||
return;
|
||||
}
|
||||
if (!Arrays.equals(buf0, 0, len0, buf1, 0, len1)) {
|
||||
System.out.println(rel + ": Data mismatch");
|
||||
countErr.incrementAndGet();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (final Exception ex) {
|
||||
System.out.println(rel + ": Exception: " + ex.getMessage());
|
||||
countErr.incrementAndGet();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
System.out.println("Took " + (System.currentTimeMillis() - start) + "ms");
|
||||
System.out.println(count.get() + " files");
|
||||
System.out.println(countErr.get() + " errors");
|
||||
}
|
||||
|
||||
}
|
||||
2
src/module-info.java
Normal file
2
src/module-info.java
Normal file
@@ -0,0 +1,2 @@
|
||||
module checkDataIntegrity {
|
||||
}
|
||||
Reference in New Issue
Block a user