diff options
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.java | 22 |
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); + } } |