Initial project
This commit is contained in:
66
src/main/java/com/imyeyu/compress/GZipDecompressor.java
Normal file
66
src/main/java/com/imyeyu/compress/GZipDecompressor.java
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user