Files
timi-compress/src/main/java/com/imyeyu/compress/Compressor.java
Timi afcc902cbf
Some checks failed
CI/CD / build-deploy (pull_request) Failing after 1m31s
v0.0.1
2026-04-01 14:09:24 +08:00

48 lines
1.0 KiB
Java

package com.imyeyu.compress;
import com.imyeyu.io.IO;
import java.io.File;
import java.io.OutputStream;
/**
* 抽象压缩器
*
* @author 夜雨
* @version 2024-06-30 10:34
*/
public abstract class Compressor extends AbstractRunner {
/**
* 将指定路径下的文件压缩到目标文件
*
* @param fromPath 源路径
* @param toFile 目标压缩文件
* @throws Exception 压缩失败
*/
public void run(String fromPath, File toFile) throws Exception {
try (OutputStream outputStream = IO.getOutputStream(toFile)) {
run(fromPath, outputStream);
outputStream.flush();
} catch (Exception exception) {
if (isInterrupt) {
IO.destroy(toFile);
}
throw exception;
}
if (isInterrupt) {
IO.destroy(toFile);
}
}
/**
* 将指定路径下的文件压缩到输出流
* 输出流由调用方管理
*
* @param fromPath 源路径
* @param toStream 目标输出流
* @throws Exception 压缩失败
*/
public abstract void run(String fromPath, OutputStream toStream) throws Exception;
}