summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java76
1 files changed, 35 insertions, 41 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java b/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java
index d4081c6..7ee46f9 100644
--- a/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java
+++ b/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java
@@ -1,7 +1,5 @@
package com.keuin.kbackupfabric.ui;
-import org.jetbrains.annotations.NotNull;
-
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -28,51 +26,47 @@ public class BackupManager {
* @return all backups.
*/
public Iterable<BackupInfo> getAllBackups() {
- return new Iterable<BackupInfo>() {
- @NotNull
- @Override
- public Iterator<BackupInfo> iterator() {
- if (backupStorageDirectory.exists()) {
- if (!backupStorageDirectory.isDirectory()) {
- throw new RuntimeException("Backup directory is not a directory.");
- }
- } else {
- if (!backupStorageDirectory.mkdirs()) {
- throw new RuntimeException("Backup directory does not exist and cannot be created.");
- }
+ return () -> {
+ if (backupStorageDirectory.exists()) {
+ if (!backupStorageDirectory.isDirectory()) {
+ throw new RuntimeException("Backup directory is not a directory.");
}
- File[] backupFiles = backupStorageDirectory.listFiles();
- if (backupFiles == null) {
- throw new RuntimeException("Cannot list files in backup directory.");
+ } else {
+ if (!backupStorageDirectory.mkdirs()) {
+ throw new RuntimeException("Backup directory does not exist and cannot be created.");
}
+ }
+ File[] backupFiles = backupStorageDirectory.listFiles();
+ if (backupFiles == null) {
+ throw new RuntimeException("Cannot list files in backup directory.");
+ }
- return new Iterator<BackupInfo>() {
- private final Iterator<File> fileIterator = Arrays.stream(backupFiles).filter(file -> {
- String name = file.getName().toLowerCase();
- return name.endsWith(".zip") || name.endsWith(".kbi");
- }).iterator();
+ return new Iterator<BackupInfo>() {
+ private final Iterator<File> fileIterator = Arrays.stream(backupFiles).filter(file -> {
+ String name = file.getName().toLowerCase();
+ return name.endsWith(".zip") || name.endsWith(".kbi");
+ }).iterator();
- @Override
- public boolean hasNext() {
- return fileIterator.hasNext();
- }
+ @Override
+ public boolean hasNext() {
+ return fileIterator.hasNext();
+ }
- @Override
- public BackupInfo next() {
- try {
- File backupFile = fileIterator.next();
- String fileName = backupFile.getName().toLowerCase();
- if (fileName.endsWith(".zip"))
- return PrimitiveBackupInfo.fromFile(backupFile);
- if (fileName.endsWith(".kbi"))
- return IncrementalBackupInfo.fromFile(backupFile);
- throw new RuntimeException("Invalid backup file extname");
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ @Override
+ public BackupInfo next() {
+ try {
+ File backupFile = fileIterator.next();
+ String fileName = backupFile.getName().toLowerCase();
+ if (fileName.endsWith(".zip"))
+ return PrimitiveBackupInfo.fromFile(backupFile);
+ if (fileName.endsWith(".kbi"))
+ return IncrementalBackupInfo.fromFile(backupFile);
+ throw new RuntimeException("Invalid backup file extname");
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- };
- }
+ }
+ };
};
}
}