summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-06-11 17:24:46 +0800
committerKeuin <[email protected]>2021-06-11 18:54:04 +0800
commit1ec5112f3487d7a2ca7aa9b1fe4825a8e3777bc3 (patch)
tree40b6cb086bb0f4f074f2c422dba491806e7f177e /src/main/java/com/keuin/kbackupfabric/operation/backup/feedback
parentfe652450ac33adc4bb15a487eff24d7b5120e1a2 (diff)
fix silent-fail IO exception in ZipUtil; Improve code quality in ZipUtil
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup/feedback')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java
index 094438c..0d99cf5 100644
--- a/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java
+++ b/src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java
@@ -3,12 +3,23 @@ package com.keuin.kbackupfabric.operation.backup.feedback;
import static com.keuin.kbackupfabric.backup.BackupFilesystemUtil.getFriendlyFileSizeString;
public class PrimitiveBackupFeedback implements BackupFeedback {
+
private final boolean success;
- private final long backupSizeBytes;
+ private final long backupSizeBytes; // if success==false, this is invalid
+ private final String message; // if success==true, this is invalid
- public PrimitiveBackupFeedback(boolean success, long backupSizeBytes) {
+ private PrimitiveBackupFeedback(boolean success, long backupSizeBytes, String message) {
this.success = success;
this.backupSizeBytes = backupSizeBytes;
+ this.message = message;
+ }
+
+ public static PrimitiveBackupFeedback createSuccessFeedback(long backupSizeBytes) {
+ return new PrimitiveBackupFeedback(true, backupSizeBytes, "");
+ }
+
+ public static PrimitiveBackupFeedback createFailFeedback(String message) {
+ return new PrimitiveBackupFeedback(false, -1, message);
}
@Override
@@ -25,6 +36,6 @@ public class PrimitiveBackupFeedback implements BackupFeedback {
if (success && backupSizeBytes >= 0)
return String.format("Backup file size: %s.", getFriendlyFileSizeString(backupSizeBytes));
else
- return "";
+ return message;
}
}