summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
diff options
context:
space:
mode:
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.java41
1 files changed, 41 insertions, 0 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 f663f20..fa411a0 100644
--- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
+++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/ObjectCollectionSerializer.java
@@ -1,6 +1,11 @@
package com.keuin.kbackupfabric.backup.incremental;
+import org.jetbrains.annotations.NotNull;
+
import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Iterator;
import java.util.Objects;
/**
@@ -39,4 +44,40 @@ public class ObjectCollectionSerializer {
}
}
}
+
+ public static Iterable<ObjectCollection2> fromDirectory(File directory) throws IOException {
+
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException("Given directory is invalid.");
+ }
+ return new Iterable<ObjectCollection2>() {
+ private final Iterator<ObjectCollection2> iter = new Iterator<ObjectCollection2>() {
+ private final Iterator<Path> i = Files.walk(directory.toPath(), 1).filter(p -> {
+ File f = p.toFile();
+ return f.isFile() && f.getName().endsWith(".kbi");
+ }).iterator();
+
+ @Override
+ public boolean hasNext() {
+ return i.hasNext();
+ }
+
+ @Override
+ public ObjectCollection2 next() {
+ try {
+ return fromFile(i.next().toFile());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ };
+
+ @NotNull
+ @Override
+ public Iterator<ObjectCollection2> iterator() {
+ return iter;
+ }
+ };
+
+ }
}