This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user