mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 13:19:02 +00:00
26 lines
660 B
Java
26 lines
660 B
Java
![]() |
package nu.marginalia.sideload;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.nio.ByteBuffer;
|
||
|
import java.nio.file.Files;
|
||
|
import java.nio.file.Path;
|
||
|
import java.util.zip.CRC32;
|
||
|
|
||
|
public class SideloadHelper {
|
||
|
public static String getCrc32FileHash(Path file) throws IOException {
|
||
|
ByteBuffer buffer = ByteBuffer.allocate(8192);
|
||
|
|
||
|
try (var channel = Files.newByteChannel(file)) {
|
||
|
CRC32 crc = new CRC32();
|
||
|
|
||
|
while (channel.read(buffer) > 0) {
|
||
|
buffer.flip();
|
||
|
crc.update(buffer);
|
||
|
buffer.clear();
|
||
|
}
|
||
|
|
||
|
return Long.toHexString(crc.getValue());
|
||
|
}
|
||
|
}
|
||
|
}
|