diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java index 0fa9d77..9b7cb83 100644 --- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java +++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java @@ -10,6 +10,8 @@ import java.util.Optional; import java.util.Set; import java.util.zip.*; +import static java.util.zip.Deflater.DEFAULT_COMPRESSION; + public final class ZipUtil { /** @@ -76,7 +78,7 @@ public final class ZipUtil { * @throws IOException IO Error * @throws ZipUtilException General exception, such as loop recursion. */ - public static void makeBackupZip(String srcPath, String zipPath, String zipFileName, BackupMetadata backupMetadata) throws IOException, ZipUtilException { + public static void makeBackupZip(String srcPath, String zipPath, String zipFileName, BackupMetadata backupMetadata, int zipLevel) throws IOException, ZipUtilException { if (srcPath == null || zipPath == null || zipFileName == null || backupMetadata == null || srcPath.isEmpty() || zipPath.isEmpty() || zipFileName.isEmpty()) { throw new IllegalArgumentException("Parameter for zip() contains null."); } @@ -113,6 +115,7 @@ public final class ZipUtil { checkedOutputStream = new CheckedOutputStream(new FileOutputStream(zipFile), new CRC32()); zipOutputStream = new ZipOutputStream(checkedOutputStream); + zipOutputStream.setLevel(zipLevel); // If with backup metadata, we serialize it and write it into file "kbackup_metadata" ZipEntry metadataEntry = new ZipEntry(BackupMetadata.metadataFileName); @@ -146,6 +149,10 @@ public final class ZipUtil { } } + public static void makeBackupZip(String srcPath, String zipPath, String zipFileName, BackupMetadata backupMetadata) throws IOException, ZipUtilException { + makeBackupZip(srcPath, zipPath, zipFileName, backupMetadata, DEFAULT_COMPRESSION); + } + /** * 解压缩zip包 * |