java.lang.Object
org.cryptomator.cryptofs.common.BackupHelper
Utility class for generating a suffix for the backup file to make it unique to its original file.
-
Method Summary
Modifier and TypeMethodDescriptionstatic PathattemptBackup(Path path) Do a best-effort attempt to back up the file at the given path.static StringgenerateFileIdSuffix(byte[] fileBytes) Computes the SHA-256 digest of the given byte array and returns a file suffix containing the first 4 bytes in hex string format.
-
Method Details
-
generateFileIdSuffix
Computes the SHA-256 digest of the given byte array and returns a file suffix containing the first 4 bytes in hex string format.- Parameters:
fileBytes- the input byte for which the digest is computed- Returns:
- "." + first 4 bytes of SHA-256 digest in hex string format
-
attemptBackup
Do a best-effort attempt to back up the file at the given path. Fails silently if a _valid_ backup already exists and fails with a log entry, if any IO error occurs while creating or reading the backup file.- Parameters:
path- The file to back up- Throws:
IOException- If the path cannot be read.
-