From 1ec5112f3487d7a2ca7aa9b1fe4825a8e3777bc3 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 11 Jun 2021 17:24:46 +0800 Subject: fix silent-fail IO exception in ZipUtil; Improve code quality in ZipUtil --- .../backup/feedback/PrimitiveBackupFeedback.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/main/java/com/keuin/kbackupfabric/operation/backup/feedback/PrimitiveBackupFeedback.java') 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; } } -- cgit v1.2.3