summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-01-13 02:49:57 +0800
committerKeuin <[email protected]>2023-01-13 02:49:57 +0800
commit5dc6e700cbcbc01833a02a193f660a286b934898 (patch)
tree72cf4cc3cfae2b3a7fb978bc0c465e329909db3e /src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java
parentff7d23b5b915f04c2b5f3614701cb56cfc605228 (diff)
Code cleanup.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java21
1 files changed, 7 insertions, 14 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java
index 50e6aa4..21111a0 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/identifier/Sha256Identifier.java
@@ -54,27 +54,20 @@ public class Sha256Identifier extends SingleHashIdentifier {
@Override
protected byte[] hash(File file) throws IOException {
+ return sha256Hash(file);
+ }
+
+ public static byte[] sha256Hash(File file) throws IOException {
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (FileInputStream inputStream = new FileInputStream(file)) {
- // This does not work. I don't know why
-// FileChannel channel = inputStream.getChannel();
-// ByteBuffer buffer = ByteBuffer.allocate(128);
-// int readLength;
-// while ((readLength = channel.read(buffer)) > 0)
-// digest.update(buffer);
-
- // This also works, without warnings
byte[] readBuffer = new byte[1024 * 1024];
+
int readLength;
- while ((readLength = inputStream.read(readBuffer)) > 0)
+ while ((readLength = inputStream.read(readBuffer)) > 0) {
digest.update(readBuffer, 0, readLength);
-
- // The below lines also works, but the IDE will complain about the while loop
-// DigestInputStream digestInputStream = new DigestInputStream(inputStream, digest);
-// while(digestInputStream.read() > 0)
-// ;
+ }
return digest.digest();
}