summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-01-25 03:12:16 +0800
committerkeuin <[email protected]>2021-01-25 03:12:16 +0800
commita817715ad4f625e355b285d67ee323e8b2006ae4 (patch)
tree5f9ffa5b18152b7efc056e5b01f9126505b69179 /src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
parent93494e7e04e05beb4f07cfabdd14c674b97a12e5 (diff)
Code refactor
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java27
1 files changed, 7 insertions, 20 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
index 3be1bfe..42e7c0c 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
@@ -7,12 +7,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
/**
* Serialize and deserialize ObjectCollection from/to the disk file.
@@ -53,19 +48,11 @@ public class ObjectCollectionSerializer {
}
public static Iterable<ObjectCollection2> fromDirectory(File directory) throws IOException {
- if (!directory.isDirectory()) {
- throw new IllegalArgumentException("Given directory is invalid.");
- }
- List<Path> pathList = new ArrayList<>();
- Files.walk(directory.toPath(), 1).filter(p -> {
- File f = p.toFile();
- return f.isFile() && f.getName().endsWith(".kbi");
- }).forEach(pathList::add);
- List<ObjectCollection2> objectList = new ArrayList<>();
- for (Path path : pathList) {
- SavedIncrementalBackup info = IncBackupInfoSerializer.fromFile(path.toFile());
- objectList.add(info.getObjectCollection());
- }
- return Collections.unmodifiableCollection(objectList);
+ List<ObjectCollection2> list = new ArrayList<>();
+ IncBackupInfoSerializer.fromDirectory(directory)
+ .forEach(o -> Optional.ofNullable(o)
+ .map(SavedIncrementalBackup::getObjectCollection)
+ .ifPresent(list::add));
+ return Collections.unmodifiableCollection(list);
}
}