Initial project
This commit is contained in:
57
src/main/java/com/imyeyu/compress/Z7Decompressor.java
Normal file
57
src/main/java/com/imyeyu/compress/Z7Decompressor.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package com.imyeyu.compress;
|
||||
|
||||
import com.imyeyu.io.IO;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
|
||||
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author 夜雨
|
||||
* @version 2024-06-30 19:42
|
||||
*/
|
||||
public class Z7Decompressor extends Decompressor {
|
||||
|
||||
@Override
|
||||
public void run(File fromFile, String toPath) throws Exception {
|
||||
toPath = new File(toPath).getAbsolutePath() + SEP;
|
||||
|
||||
int total = 0;
|
||||
if (progressCallback != null) {
|
||||
SevenZFile file = SevenZFile.builder().setFile(fromFile).get();
|
||||
try (file) {
|
||||
while (file.getNextEntry() != null) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
}
|
||||
SevenZFile file = SevenZFile.builder().setFile(fromFile).get();
|
||||
SevenZArchiveEntry entry;
|
||||
for (int i = 0; (entry = file.getNextEntry()) != null; i++) {
|
||||
if (entry.isDirectory()) {
|
||||
IO.dir(IO.fitPath(toPath) + entry.getName());
|
||||
} else {
|
||||
File toFile = IO.file(toPath + entry.getName());
|
||||
byte[] buffer = new byte[(int) entry.getSize()];
|
||||
file.read(buffer, 0, buffer.length);
|
||||
IO.toFile(toFile, buffer);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user