summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.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/ObjectCollectionFactory.java
parentff7d23b5b915f04c2b5f3614701cb56cfc605228 (diff)
Code cleanup.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java
index 04ae96e..095108b 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionFactory.java
@@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
import java.util.function.Supplier;
+import java.util.stream.Stream;
/**
* Incremental backup is implemented as git-like file collection.
@@ -45,17 +46,19 @@ public class ObjectCollectionFactory<T extends ObjectIdentifier> {
throw new IllegalArgumentException("given file is not a directory");
Set<File> files = new HashSet<>();
- for (Iterator<Path> iter = Files.walk(directory.toPath(), 1).iterator(); iter.hasNext(); ) {
- Path path = iter.next();
- if (Files.isSameFile(path, directory.toPath()))
- continue;
- File file = path.toFile();
- if (file.isDirectory()) {
- subCollections.put(file.getName(), fromDirectory(file, ignoredFiles));
- } else if (!ignoredFiles.contains(file.getName())) {
- files.add(file); // add to the set to be processed
- } else {
- PrintUtil.info(String.format("Skipping file %s.", file.getName()));
+ try (Stream<Path> walk = Files.walk(directory.toPath(), 1)) {
+ for (Iterator<Path> iter = walk.iterator(); iter.hasNext(); ) {
+ Path path = iter.next();
+ if (Files.isSameFile(path, directory.toPath()))
+ continue;
+ File file = path.toFile();
+ if (file.isDirectory()) {
+ subCollections.put(file.getName(), fromDirectory(file, ignoredFiles));
+ } else if (!ignoredFiles.contains(file.getName())) {
+ files.add(file); // add to the set to be processed
+ } else {
+ PrintUtil.info(String.format("Skipping file %s.", file.getName()));
+ }
}
}
@@ -125,7 +128,7 @@ public class ObjectCollectionFactory<T extends ObjectIdentifier> {
public void process() {
workers.clear();
for (int i = 0; i < threads; i++) {
- ParallelWorker<Res> worker = new ParallelWorker<Res>(taskList, consumer, i);
+ ParallelWorker<Res> worker = new ParallelWorker<>(taskList, consumer, i);
workers.add(worker);
worker.start();
}