Initial project

This commit is contained in:
Timi
2025-07-14 15:27:37 +08:00
parent 063520868e
commit 47f1c9520e
27 changed files with 1043 additions and 94 deletions

View File

@@ -0,0 +1,50 @@
package com.imyeyu.compress;
import com.imyeyu.io.IO;
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZOutputFile;
import java.io.File;
import java.util.List;
/**
* @author 夜雨
* @version 2024-06-30 19:40
*/
public class Z7Compressor extends Compressor {
@Override
public void run(String fromPath, File toFile) throws Exception {
List<File> files = IO.listFile(new File(fromPath));
String basePath = files.getFirst().getParentFile().getAbsolutePath();
SevenZOutputFile out = new SevenZOutputFile(toFile);
SevenZArchiveEntry entry;
for (int i = 0, total = files.size(); i < total; i++) {
String name = files.get(i).getAbsolutePath().substring(basePath.length() + 1);
entry = out.createArchiveEntry(files.get(i), name.replaceAll("\\\\", "/"));
out.putArchiveEntry(entry);
out.write(IO.toBytes(files.get(i)));
out.closeArchiveEntry();
if (isPause) {
synchronized (pauseLock) {
pauseLock.wait();
}
}
if (fileCallback != null) {
fileCallback.handler(toFile);
}
if (progressCallback != null) {
progressCallback.handler(1D * i / total);
}
if (isInterrupt) {
break;
}
}
out.close();
if (isInterrupt) {
IO.destroy(toFile);
}
}
}