v0.0.4 #7
@@ -46,10 +46,10 @@ public class GZipCompressor extends Compressor<GZipCompressor> {
|
||||
List<File> files = IO.listFile(fromFile);
|
||||
String basePath = files.getFirst().getParentFile().getAbsolutePath();
|
||||
initByteProgress(IO.calcSize(fromFile));
|
||||
try (
|
||||
GzipCompressorOutputStream gzipOutputStream = new GzipCompressorOutputStream(new BufferedOutputStream(nonClosing(toStream)));
|
||||
TarArchiveOutputStream tarOutputStream = new TarArchiveOutputStream(gzipOutputStream)
|
||||
) {
|
||||
TarArchiveOutputStream tarOutputStream = null;
|
||||
try {
|
||||
tarOutputStream = new TarArchiveOutputStream(gzipOutputStream);
|
||||
for (File sourceFile : files) {
|
||||
String name = sourceFile.getAbsolutePath().substring(basePath.length() + 1);
|
||||
TarArchiveEntry tarEntry = new TarArchiveEntry(sourceFile, normalizeEntryName(name));
|
||||
@@ -61,9 +61,13 @@ public class GZipCompressor extends Compressor<GZipCompressor> {
|
||||
handleFile(sourceFile);
|
||||
}
|
||||
tarOutputStream.finish();
|
||||
gzipOutputStream.finish();
|
||||
finishProgress();
|
||||
} finally {
|
||||
if (tarOutputStream != null) {
|
||||
tarOutputStream.close();
|
||||
} else {
|
||||
gzipOutputStream.close();
|
||||
}
|
||||
resetProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -52,8 +53,8 @@ public class GzipTest {
|
||||
|
||||
@Test
|
||||
public void testCompressToStream() throws Exception {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
CompressType.GZIP.ofCompress("testSrc").toStream(outputStream);
|
||||
try (OutputStream os = IO.getOutputStream(IO.file("testOut/test.tar.gz"))) {
|
||||
CompressType.GZIP.ofCompress("testSrc").toStream(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@@ -52,8 +53,8 @@ public class TarTest {
|
||||
|
||||
@Test
|
||||
public void testCompressToStream() throws Exception {
|
||||
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||
CompressType.TAR.ofCompress("testSrc").toStream(outputStream);
|
||||
try (OutputStream os = IO.getOutputStream(IO.file("testOut/test.tar"))) {
|
||||
CompressType.TAR.ofCompress("testSrc").toStream(os);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user