Use a buffered digest where possible instead of reading the whole file contents into memory.

This commit is contained in:
CalDescent 2021-10-30 18:21:06 +01:00
parent 60f96d15bd
commit bada4fd140
2 changed files with 3 additions and 5 deletions

View File

@ -350,7 +350,7 @@ public class ArbitraryDataDiff {
private static byte[] digestFromPath(Path path) { private static byte[] digestFromPath(Path path) {
try { try {
return Crypto.digest(Files.readAllBytes(path)); return Crypto.digest(path.toFile());
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} }

View File

@ -111,8 +111,7 @@ public class ArbitraryDataFile {
File file = path.toFile(); File file = path.toFile();
if (file.exists()) { if (file.exists()) {
try { try {
byte[] fileContent = Files.readAllBytes(file.toPath()); byte[] digest = Crypto.digest(file);
byte[] digest = Crypto.digest(fileContent);
ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(digest); ArbitraryDataFile arbitraryDataFile = ArbitraryDataFile.fromHash(digest);
// Copy file to data directory if needed // Copy file to data directory if needed
@ -502,8 +501,7 @@ public class ArbitraryDataFile {
File file = this.getFile(); File file = this.getFile();
if (file != null && file.exists()) { if (file != null && file.exists()) {
try { try {
byte[] fileContent = Files.readAllBytes(file.toPath()); return Crypto.digest(file);
return Crypto.digest(fileContent);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Couldn't compute digest for ArbitraryDataFile"); LOGGER.error("Couldn't compute digest for ArbitraryDataFile");