From 61ade9adad4668494dfc32da7751e1b86251dc97 Mon Sep 17 00:00:00 2001 From: Keuin Date: Mon, 30 Nov 2020 13:15:15 +0800 Subject: Implementing incremental backup --- .../keuin/kbackupfabric/util/FilesystemUtil.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java (limited to 'src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java') diff --git a/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java b/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java new file mode 100644 index 0000000..7f74725 --- /dev/null +++ b/src/main/java/com/keuin/kbackupfabric/util/FilesystemUtil.java @@ -0,0 +1,33 @@ +package com.keuin.kbackupfabric.util; + +import java.io.File; + +public class FilesystemUtil { + + /** + * Get file sizes in bytes. + * @param parentDirectory path to specific file. + * @param fileName file name. + * @return bytes. If failed, return -1. + */ + public static long getFileSizeBytes(String parentDirectory, String fileName) { + long fileSize = -1; + try{ + File backupZipFile = new File(parentDirectory, fileName); + fileSize = backupZipFile.length(); + } catch (SecurityException ignored){ + } + return fileSize; + } + + public static long getFileSizeBytes(String filePath) { + long fileSize = -1; + try{ + File backupZipFile = new File(filePath); + fileSize = backupZipFile.length(); + } catch (SecurityException ignored){ + } + return fileSize; + } + +} -- cgit v1.2.3