v0.0.2
All checks were successful
CI/CD / build-deploy (pull_request) Successful in 14s

This commit is contained in:
Timi
2026-04-01 22:47:09 +08:00
parent a24b1855aa
commit 56dec33c94
17 changed files with 550 additions and 69 deletions

View File

@@ -8,22 +8,23 @@ import java.io.InputStream;
/**
* 抽象解压器
*
* @param <T> 解压器类型
* @author 夜雨
* @version 2024-06-30 18:02
*/
public abstract class Decompressor extends AbstractRunner {
public abstract class Decompressor<T extends Decompressor<T>> extends AbstractRunner<T> {
/**
* 将压缩文件解压到目标目录
*
* @param fromFile 源压缩文件
* @param toPath 目标目录
* @return 当前解压器
* @throws Exception 解压失败
*/
public void run(File fromFile, String toPath) throws Exception {
try (InputStream inputStream = IO.getInputStream(fromFile)) {
run(inputStream, toPath);
}
public T run(File fromFile, String toPath) throws Exception {
doRunFromFile(fromFile, toPath);
return self();
}
/**
@@ -32,7 +33,33 @@ public abstract class Decompressor extends AbstractRunner {
*
* @param fromStream 源压缩输入流
* @param toPath 目标目录
* @return 当前解压器
* @throws Exception 解压失败
*/
public abstract void run(InputStream fromStream, String toPath) throws Exception;
public T run(InputStream fromStream, String toPath) throws Exception {
doRun(fromStream, toPath);
return self();
}
/**
* 执行从文件解压
*
* @param fromFile 源压缩文件
* @param toPath 目标目录
* @throws Exception 解压失败
*/
protected void doRunFromFile(File fromFile, String toPath) throws Exception {
try (InputStream inputStream = IO.getInputStream(fromFile)) {
doRun(inputStream, toPath);
}
}
/**
* 执行从输入流解压
*
* @param fromStream 源压缩输入流
* @param toPath 目标目录
* @throws Exception 解压失败
*/
protected abstract void doRun(InputStream fromStream, String toPath) throws Exception;
}