summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.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/serializer/IncBackupInfoSerializer.java
parent93494e7e04e05beb4f07cfabdd14c674b97a12e5 (diff)
Code refactor
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java
index e79c02f..f17217a 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/serializer/IncBackupInfoSerializer.java
@@ -7,6 +7,11 @@ import com.keuin.kbackupfabric.backup.name.IncrementalBackupFileNameEncoder;
import com.keuin.kbackupfabric.util.backup.incremental.ObjectCollection;
import java.io.*;
+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;
public class IncBackupInfoSerializer {
@@ -66,4 +71,21 @@ public class IncBackupInfoSerializer {
}
}
}
+
+ public static Iterable<SavedIncrementalBackup> 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<SavedIncrementalBackup> objectList = new ArrayList<>();
+ for (Path path : pathList) {
+ SavedIncrementalBackup info = IncBackupInfoSerializer.fromFile(path.toFile());
+ objectList.add(info);
+ }
+ return Collections.unmodifiableCollection(objectList);
+ }
}