BAEL-6403 - Extracting a Tar File in Java (#14240)

* code 1

* sibling module readme

* new module

* review 1

* review 2
This commit is contained in:
Ulisses Lima
2023-06-24 05:43:02 -03:00
committed by GitHub
parent faf6b79e86
commit 7d58a88529
16 changed files with 360 additions and 1 deletions
@@ -0,0 +1,40 @@
package com.baeldung.commons.untar;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.junit.Test;
import com.baeldung.commons.untar.impl.TarExtractorAnt;
public class TarExtractorAntUnitTest {
@Test
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/ant");
new TarExtractorAnt(Resources.tarFile(), false, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
@Test
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/ant-gz");
new TarExtractorAnt(Resources.tarGzFile(), true, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
}
@@ -0,0 +1,40 @@
package com.baeldung.commons.untar;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import com.baeldung.commons.untar.impl.TarExtractorCommonsCompress;
public class TarExtractorCommonsCompressUnitTest {
@Test
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/commons-compress");
new TarExtractorCommonsCompress(Resources.tarFile(), false, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
@Test
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/commons-compress-gz");
new TarExtractorCommonsCompress(Resources.tarGzFile(), true, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
}
@@ -0,0 +1,40 @@
package com.baeldung.commons.untar;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;
import org.junit.Test;
import com.baeldung.commons.untar.impl.TarExtractorVfs;
public class TarExtractorVfsUnitTest {
@Test
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/vfs");
new TarExtractorVfs(Resources.tarFile(), false, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
@Test
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/vfs-gz");
new TarExtractorVfs(Resources.tarGzFile(), true, destination).untar();
try (Stream<Path> files = Files.list(destination)) {
assertTrue(files.findFirst()
.isPresent());
}
}
}