Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(snapshots): Replace Stream.toList and the for each cycle to Stream.forEachOrdered #12576

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,9 +9,10 @@

import java.io.IOException;
import java.io.RandomAccessFile;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Stream;

final class SnapshotChecksum {

Expand All @@ -38,7 +39,7 @@ public static SfvChecksum read(final Path checksumPath) throws IOException {
public static SfvChecksum calculate(final Path snapshotDirectory) throws IOException {
try (final var fileStream =
Files.list(snapshotDirectory).filter(SnapshotChecksum::isNotMetadataFile).sorted()) {
final SfvChecksum sfvChecksum = createCombinedChecksum(fileStream.toList());
final SfvChecksum sfvChecksum = createCombinedChecksum(fileStream);

// While persisting transient snapshot, the checksum of metadata file is added at the end.
// Hence when we recalculate the checksum, we must follow the same order. Otherwise base on
Expand Down Expand Up @@ -70,11 +71,16 @@ public static void persist(final Path checksumPath, final SfvChecksum checksum)
*
* @return the SfvChecksum object
*/
private static SfvChecksum createCombinedChecksum(final List<Path> files) throws IOException {
private static SfvChecksum createCombinedChecksum(final Stream<Path> files) {
final SfvChecksum checksum = new SfvChecksum();
for (final var f : files) {
checksum.updateFromFile(f);
}
files.forEachOrdered(
path -> {
try {
checksum.updateFromFile(path);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
return checksum;
}
}