diff options
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier')
2 files changed, 14 insertions, 11 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/ObjectIdentifier.java b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/ObjectIdentifier.java index 6744616..aece07d 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/ObjectIdentifier.java +++ b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/ObjectIdentifier.java @@ -1,11 +1,13 @@ package com.keuin.kbackupfabric.util.backup.incremental.identifier; +import java.io.Serializable; + /** * The identifier distinguishing files in the object collection. * It should be based on cryptographic hash function in order to prevent possible attacks to the backup system. * All identifiers should be immutable and implement their own equals method. * Immutable. */ -public interface ObjectIdentifier { +public interface ObjectIdentifier extends Serializable { String getIdentification(); } diff --git a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/Sha256Identifier.java b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/Sha256Identifier.java index 64716ed..9ecf2d3 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/Sha256Identifier.java +++ b/src/main/java/com/keuin/kbackupfabric/util/backup/incremental/identifier/Sha256Identifier.java @@ -41,27 +41,28 @@ public class Sha256Identifier extends SingleHashIdentifier { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); - FileInputStream inputStream = new FileInputStream(file); - - // This does not work. I don't know why + 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) - digest.update(readBuffer,0, readLength); + // This also works, without warnings + byte[] readBuffer = new byte[1024 * 1024]; + int readLength; + 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 + // 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(); + return digest.digest(); + } + } catch (NoSuchAlgorithmException ignored) { // this shouldn't happen return new byte[SHA256_LENGTH]; |