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:
+40
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
+40
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user