|
@@ -31,13 +31,14 @@ public class Zip4jUtil {
|
|
* @param files
|
|
* @param files
|
|
*/
|
|
*/
|
|
public static void zipFile(String scrPath, List<File> files) {
|
|
public static void zipFile(String scrPath, List<File> files) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
|
|
+ if (!scrPath.endsWith(".zip")) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtils.isEmpty(files)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
- if (!scrPath.endsWith(".zip")) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
|
|
- }
|
|
|
|
- if (CollectionUtils.isEmpty(files)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
|
|
|
|
- }
|
|
|
|
// 生成的压缩文件
|
|
// 生成的压缩文件
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipParameters parameters = new ZipParameters();
|
|
ZipParameters parameters = new ZipParameters();
|
|
@@ -66,12 +67,13 @@ public class Zip4jUtil {
|
|
*
|
|
*
|
|
* @param scrPath
|
|
* @param scrPath
|
|
* @param destPath
|
|
* @param destPath
|
|
- * @throws ZipException
|
|
|
|
*/
|
|
*/
|
|
- public static void zipFile(String scrPath, String destPath) throws ZipException {
|
|
|
|
|
|
+ public static void zipFile(String scrPath, String destPath) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
if (!scrPath.endsWith(".zip")) {
|
|
if (!scrPath.endsWith(".zip")) {
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
}
|
|
}
|
|
|
|
+ Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩路径不能为空"));
|
|
try {
|
|
try {
|
|
// 生成的压缩文件
|
|
// 生成的压缩文件
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
@@ -108,13 +110,15 @@ public class Zip4jUtil {
|
|
* @param password
|
|
* @param password
|
|
* @throws ZipException
|
|
* @throws ZipException
|
|
*/
|
|
*/
|
|
- public static void zipEncryptFile(String scrPath, List<File> files, String password) throws ZipException {
|
|
|
|
|
|
+ public static void zipEncryptFile(String scrPath, List<File> files, String password) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
if (!scrPath.endsWith(".zip")) {
|
|
if (!scrPath.endsWith(".zip")) {
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
}
|
|
}
|
|
if (CollectionUtils.isEmpty(files)) {
|
|
if (CollectionUtils.isEmpty(files)) {
|
|
throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
|
|
throw ExceptionResultEnum.ERROR.exception("没有待压缩的文件");
|
|
}
|
|
}
|
|
|
|
+ Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
|
|
try {
|
|
try {
|
|
// 生成的压缩文件
|
|
// 生成的压缩文件
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
@@ -151,12 +155,14 @@ public class Zip4jUtil {
|
|
* @param scrPath
|
|
* @param scrPath
|
|
* @param destPath
|
|
* @param destPath
|
|
* @param password
|
|
* @param password
|
|
- * @throws ZipException
|
|
|
|
*/
|
|
*/
|
|
- public static void zipEncryptFile(String scrPath, String destPath, String password) throws ZipException {
|
|
|
|
|
|
+ public static void zipEncryptFile(String scrPath, String destPath, String password) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
if (!scrPath.endsWith(".zip")) {
|
|
if (!scrPath.endsWith(".zip")) {
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
throw ExceptionResultEnum.ERROR.exception("压缩文件必须为zip");
|
|
}
|
|
}
|
|
|
|
+ Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩路径不能为空"));
|
|
|
|
+ Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("压缩密码不能为空"));
|
|
try {
|
|
try {
|
|
// 生成的压缩文件
|
|
// 生成的压缩文件
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
@@ -198,6 +204,8 @@ public class Zip4jUtil {
|
|
* @param destPath
|
|
* @param destPath
|
|
*/
|
|
*/
|
|
public static void unzip(String scrPath, String destPath) {
|
|
public static void unzip(String scrPath, String destPath) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
|
|
+ Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压路径不能为空"));
|
|
try {
|
|
try {
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
zipFile.extractAll(destPath);
|
|
zipFile.extractAll(destPath);
|
|
@@ -215,6 +223,8 @@ public class Zip4jUtil {
|
|
* @param password
|
|
* @param password
|
|
*/
|
|
*/
|
|
public static void unzipEncryptFile(String scrPath, String destPath, String password) {
|
|
public static void unzipEncryptFile(String scrPath, String destPath, String password) {
|
|
|
|
+ Optional.ofNullable(scrPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("原始路径不能为空"));
|
|
|
|
+ Optional.ofNullable(destPath).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压路径不能为空"));
|
|
Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压密码不能为空"));
|
|
Optional.ofNullable(password).orElseThrow(() -> ExceptionResultEnum.ERROR.exception("解压密码不能为空"));
|
|
try {
|
|
try {
|
|
ZipFile zipFile = new ZipFile(scrPath);
|
|
ZipFile zipFile = new ZipFile(scrPath);
|