summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-04-23 15:11:05 +0800
committerkeuin <[email protected]>2020-04-23 15:11:05 +0800
commit597cc299f02ae4b9577d9cccc5653570fedca639 (patch)
tree1e78065fb5f7de498294eaecaf28a5fed34b929b /src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
parent720e8ec8eeb69d24afbb6b14068563cde2d470f0 (diff)
Optimize code redundancy.
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
index 1ceeb60..fec4436 100644
--- a/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
+++ b/src/main/java/com/keuin/kbackupfabric/util/ZipUtil.java
@@ -43,7 +43,7 @@ public final class ZipUtil {
else {
// 压缩目录中的文件或子目录
File[] childFileList = file.listFiles();
- if(childFileList != null) {
+ if (childFileList != null) {
for (File value : childFileList)
zip(srcRootDir, value, zos);
}
@@ -56,7 +56,7 @@ public final class ZipUtil {
* @param srcPath 要压缩的源文件路径。如果是目录,则将递归压缩这个目录及其所有子文件、子目录树。
* @param zipPath 压缩文件保存的路径。注意:zipPath不能是srcPath路径下的子文件夹
* @param zipFileName 压缩文件名
- * @throws IOException IO Error
+ * @throws IOException IO Error
* @throws ZipUtilException General exception, such as loop recursion or invalid input.
*/
public static void zip(String srcPath, String zipPath, String zipFileName) throws IOException, ZipUtilException {
@@ -76,8 +76,8 @@ public final class ZipUtil {
//判断压缩文件保存的路径是否存在,如果不存在,则创建目录
File zipDir = new File(zipPath);
if (!zipDir.exists() || !zipDir.isDirectory()) {
- if(!zipDir.mkdirs()) {
- throw new IOException(String.format("Failed to make directory tree %s",zipDir.toString()));
+ if (!zipDir.mkdirs()) {
+ throw new IOException(String.format("Failed to make directory tree %s", zipDir.toString()));
}
}
@@ -89,8 +89,8 @@ public final class ZipUtil {
SecurityManager securityManager = new SecurityManager();
securityManager.checkDelete(zipFilePath);
//删除已存在的目标文件
- if(!zipFile.delete()) {
- throw new IOException(String.format("Failed to delete existing file %s",zipFile.toString()));
+ if (!zipFile.delete()) {
+ throw new IOException(String.format("Failed to delete existing file %s", zipFile.toString()));
}
}
@@ -143,8 +143,8 @@ public final class ZipUtil {
// 创建解压缩文件保存的路径
File unzipFileDir = new File(unzipFilePath);
if (!unzipFileDir.exists() || !unzipFileDir.isDirectory()) {
- if(!unzipFileDir.mkdirs())
- throw new IOException(String.format("Failed to make directory tree %s",unzipFileDir.toString()));
+ if (!unzipFileDir.mkdirs())
+ throw new IOException(String.format("Failed to make directory tree %s", unzipFileDir.toString()));
}
// 开始解压
@@ -173,8 +173,8 @@ public final class ZipUtil {
entryDir = new File(entryDirPath);
// 如果文件夹路径不存在,则创建文件夹
if (!entryDir.exists() || !entryDir.isDirectory()) {
- if(!entryDir.mkdirs())
- throw new IOException(String.format("Failed to make directory tree %s",entryDir.toString()));
+ if (!entryDir.mkdirs())
+ throw new IOException(String.format("Failed to make directory tree %s", entryDir.toString()));
}
// 创建解压文件
@@ -184,13 +184,13 @@ public final class ZipUtil {
SecurityManager securityManager = new SecurityManager();
securityManager.checkDelete(entryFilePath);
// 删除已存在的目标文件
- if(!entryFile.delete())
- throw new IOException(String.format("Failed to delete existing file %s",entryFile.toString()));
+ if (!entryFile.delete())
+ throw new IOException(String.format("Failed to delete existing file %s", entryFile.toString()));
}
if (entry.isDirectory()) {
// If the entry is a directory, we make its corresponding directory.
- if(!entryFile.mkdir())
- throw new IOException(String.format("Failed to create directory %s",entryFile.toString()));
+ if (!entryFile.mkdir())
+ throw new IOException(String.format("Failed to create directory %s", entryFile.toString()));
} else {
// Is a file, we write the data
// 写入文件