mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -10,14 +10,15 @@ import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void zipTest(){
|
||||
public void zipTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.zip");
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.ZIP, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
.add(FileUtil.file("d:/Java"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
@@ -26,10 +27,10 @@ public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tarTest(){
|
||||
public void tarTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.tar");
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.TAR, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
.add(FileUtil.file("d:/Java"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
@@ -38,10 +39,10 @@ public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void cpioTest(){
|
||||
public void cpioTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.cpio");
|
||||
StreamArchiver.of(CharsetUtil.UTF_8, ArchiveStreamFactory.CPIO, file)
|
||||
.add(FileUtil.file("d:/Java"), (f)->{
|
||||
.add(FileUtil.file("d:/Java"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
@@ -50,10 +51,22 @@ public class ArchiverTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void sevenZTest(){
|
||||
public void sevenZTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.7z");
|
||||
CompressUtil.createArchiver(CharsetUtil.UTF_8, ArchiveStreamFactory.SEVEN_Z, file)
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.6.3"), (f)->{
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.8.1"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
.finish().close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tgzTest() {
|
||||
final File file = FileUtil.file("d:/test/compress/test.tgz");
|
||||
CompressUtil.createArchiver(CharsetUtil.UTF_8, "tgz", file)
|
||||
.add(FileUtil.file("d:/Java/apache-maven-3.8.1"), (f) -> {
|
||||
Console.log("Add: {}", f.getPath());
|
||||
return true;
|
||||
})
|
||||
|
@@ -27,4 +27,15 @@ public class ExtractorTest {
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/compress/test2/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void tgzTest(){
|
||||
Extractor extractor = CompressUtil.createExtractor(
|
||||
CharsetUtil.defaultCharset(),
|
||||
"tgz",
|
||||
FileUtil.file("d:/test/test.tgz"));
|
||||
|
||||
extractor.extract(FileUtil.file("d:/test/tgz/"));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user