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,66 @@
package com.imyeyu.compress;
import com.imyeyu.io.IO;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import java.io.File;
import java.io.InputStream;
/**
* @author 夜雨
* @version 2024-06-30 19:47
*/
public class GZipDecompressor extends Decompressor {
@Override
public void run(File fromFile, String toPath) throws Exception {
InputStream is = IO.getInputStream(fromFile);
GzipCompressorInputStream gzipIS = new GzipCompressorInputStream(is);
TarArchiveInputStream tarIS = new TarArchiveInputStream(gzipIS);
int total = 0;
{
TarArchiveEntry entry;
while ((entry = tarIS.getNextEntry()) != null) {
if (!entry.isDirectory()) {
total++;
}
}
}
tarIS.close();
is.close();
is = IO.getInputStream(fromFile);
tarIS = new TarArchiveInputStream(is);
TarArchiveEntry entry;
for (int i = 0; (entry = tarIS.getNextEntry()) != null; i++) {
String path = IO.fitPath(toPath) + entry.getName();
if (entry.isDirectory()) {
IO.dir(path);
} else {
File toFile = IO.file(path);
IO.toFile(toFile, tarIS);
if (fileCallback != null) {
fileCallback.handler(toFile);
}
}
if (isPause) {
synchronized (pauseLock) {
pauseLock.wait();
}
}
if (progressCallback != null && total != -1) {
progressCallback.handler(1D * i / total);
}
if (isInterrupt) {
break;
}
}
tarIS.close();
gzipIS.close();
is.close();
}
}