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