This commit is contained in:
Looly
2022-07-29 23:05:20 +08:00
parent a36a970341
commit 7769822e11
17 changed files with 237 additions and 27 deletions

View File

@@ -11,6 +11,7 @@ import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import java.io.File;
import java.io.IOException;
@@ -78,6 +79,16 @@ public class StreamArchiver implements Archiver {
* @param targetStream 归档输出的流
*/
public StreamArchiver(final Charset charset, final String archiverName, final OutputStream targetStream) {
if("tgz".equalsIgnoreCase(archiverName) || "tar.gz".equalsIgnoreCase(archiverName)){
//issue#I5J33E支持tgz格式解压
try {
this.out = new TarArchiveOutputStream(new GzipCompressorOutputStream(targetStream));
} catch (IOException e) {
throw new IORuntimeException(e);
}
return;
}
final ArchiveStreamFactory factory = new ArchiveStreamFactory(charset.name());
try {
this.out = factory.createArchiveOutputStream(archiverName, targetStream);

View File

@@ -10,6 +10,8 @@ import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import java.io.File;
import java.io.IOException;
@@ -71,6 +73,13 @@ public class StreamExtractor implements Extractor {
in = IoUtil.toBuffered(in);
if (StrUtil.isBlank(archiverName)) {
this.in = factory.createArchiveInputStream(in);
} else if("tgz".equalsIgnoreCase(archiverName) || "tar.gz".equalsIgnoreCase(archiverName)){
//issue#I5J33E支持tgz格式解压
try {
this.in = new TarArchiveInputStream(new GzipCompressorInputStream(in));
} catch (IOException e) {
throw new IORuntimeException(e);
}
} else {
this.in = factory.createArchiveInputStream(archiverName, in);
}