removing unrelated code
This commit is contained in:
parent
80e0f8b2e6
commit
c697704d9d
@ -1,7 +0,0 @@
|
|||||||
## Apache Commons
|
|
||||||
|
|
||||||
This module contains articles about Apache Commons libraries.
|
|
||||||
|
|
||||||
### Relevant articles
|
|
||||||
|
|
||||||
- More articles: [[<--prev]](../libraries-apache-commons)
|
|
@ -1 +0,0 @@
|
|||||||
log4j.rootLogger=INFO, stdout
|
|
@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>libraries-apache-commons-2</artifactId>
|
|
||||||
<name>libraries-apache-commons-2</name>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-compress</artifactId>
|
|
||||||
<version>${commons-compress.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.ant</groupId>
|
|
||||||
<artifactId>ant</artifactId>
|
|
||||||
<version>${ant.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-vfs2</artifactId>
|
|
||||||
<version>${commons-vfs2.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<commons-compress.version>1.23.0</commons-compress.version>
|
|
||||||
<ant.version>1.10.13</ant.version>
|
|
||||||
<commons-vfs2.version>2.9.0</commons-vfs2.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,39 +0,0 @@
|
|||||||
package com.baeldung.commons.untar;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public abstract class TarExtractor {
|
|
||||||
|
|
||||||
private InputStream tarStream;
|
|
||||||
private boolean gzip;
|
|
||||||
private Path destination;
|
|
||||||
|
|
||||||
public TarExtractor(InputStream in, boolean gzip, Path destination) throws IOException {
|
|
||||||
this.tarStream = in;
|
|
||||||
this.gzip = gzip;
|
|
||||||
this.destination = destination;
|
|
||||||
|
|
||||||
Files.createDirectories(destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TarExtractor(Path tarFile, Path destination) throws IOException {
|
|
||||||
this(Files.newInputStream(tarFile), tarFile.endsWith("gz"), destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Path getDestination() {
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getTarStream() {
|
|
||||||
return tarStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGzip() {
|
|
||||||
return gzip;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public void untar() throws IOException;
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
package com.baeldung.commons.untar.impl;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.zip.GZIPInputStream;
|
|
||||||
|
|
||||||
import org.apache.tools.tar.TarEntry;
|
|
||||||
import org.apache.tools.tar.TarInputStream;
|
|
||||||
|
|
||||||
import com.baeldung.commons.untar.TarExtractor;
|
|
||||||
|
|
||||||
public class TarExtractorAnt extends TarExtractor {
|
|
||||||
|
|
||||||
public TarExtractorAnt(InputStream in, boolean gzip, Path destination) throws IOException {
|
|
||||||
super(in, gzip, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void untar() throws IOException {
|
|
||||||
try (TarInputStream tar = new TarInputStream(new BufferedInputStream( //
|
|
||||||
isGzip() ? new GZIPInputStream(getTarStream()) : getTarStream()))) {
|
|
||||||
TarEntry entry;
|
|
||||||
while ((entry = tar.getNextEntry()) != null) {
|
|
||||||
Path extractTo = getDestination().resolve(entry.getName());
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
Files.createDirectories(extractTo);
|
|
||||||
} else {
|
|
||||||
Files.copy(tar, extractTo, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,38 +0,0 @@
|
|||||||
package com.baeldung.commons.untar.impl;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
|
|
||||||
import org.apache.commons.compress.archivers.ArchiveEntry;
|
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
|
||||||
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
|
|
||||||
|
|
||||||
import com.baeldung.commons.untar.TarExtractor;
|
|
||||||
|
|
||||||
public class TarExtractorCommonsCompress extends TarExtractor {
|
|
||||||
|
|
||||||
public TarExtractorCommonsCompress(InputStream in, boolean gzip, Path destination) throws IOException {
|
|
||||||
super(in, gzip, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void untar() throws IOException {
|
|
||||||
try (BufferedInputStream inputStream = new BufferedInputStream(getTarStream()); //
|
|
||||||
TarArchiveInputStream tar = new TarArchiveInputStream( //
|
|
||||||
isGzip() ? new GzipCompressorInputStream(inputStream) : inputStream)) {
|
|
||||||
ArchiveEntry entry;
|
|
||||||
while ((entry = tar.getNextEntry()) != null) {
|
|
||||||
Path extractTo = getDestination().resolve(entry.getName());
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
Files.createDirectories(extractTo);
|
|
||||||
} else {
|
|
||||||
Files.copy(tar, extractTo, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package com.baeldung.commons.untar.impl;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.apache.commons.vfs2.FileContent;
|
|
||||||
import org.apache.commons.vfs2.FileObject;
|
|
||||||
import org.apache.commons.vfs2.FileSystemManager;
|
|
||||||
import org.apache.commons.vfs2.FileType;
|
|
||||||
import org.apache.commons.vfs2.VFS;
|
|
||||||
|
|
||||||
import com.baeldung.commons.untar.TarExtractor;
|
|
||||||
|
|
||||||
public class TarExtractorVfs extends TarExtractor {
|
|
||||||
|
|
||||||
public TarExtractorVfs(InputStream in, boolean gzip, Path destination) throws IOException {
|
|
||||||
super(in, gzip, destination);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void untar() throws IOException {
|
|
||||||
Path tmpTar = Files.createTempFile("temp", isGzip() ? ".tar.gz" : ".tar");
|
|
||||||
Files.copy(getTarStream(), tmpTar, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
|
|
||||||
FileSystemManager fsManager = VFS.getManager();
|
|
||||||
String uri = String.format("%s:file://%s", isGzip() ? "tgz" : "tar", tmpTar.toString());
|
|
||||||
FileObject tar = fsManager.resolveFile(uri);
|
|
||||||
|
|
||||||
Iterator<FileObject> contents = tar.iterator();
|
|
||||||
while (contents.hasNext()) {
|
|
||||||
FileObject entry = contents.next();
|
|
||||||
|
|
||||||
Path extractTo = Paths.get(getDestination().toString(), entry.getName()
|
|
||||||
.getPath());
|
|
||||||
|
|
||||||
if (entry.isReadable() && entry.getType() == FileType.FILE) {
|
|
||||||
Files.createDirectories(extractTo.getParent());
|
|
||||||
|
|
||||||
try (FileContent content = entry.getContent(); InputStream stream = content.getInputStream()) {
|
|
||||||
Files.copy(stream, extractTo, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Files.delete(tmpTar);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<configuration>
|
|
||||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
|
||||||
<encoder>
|
|
||||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
|
||||||
</pattern>
|
|
||||||
</encoder>
|
|
||||||
</appender>
|
|
||||||
|
|
||||||
<root level="INFO">
|
|
||||||
<appender-ref ref="STDOUT" />
|
|
||||||
</root>
|
|
||||||
</configuration>
|
|
@ -1,14 +0,0 @@
|
|||||||
package com.baeldung.commons.untar;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public interface Resources {
|
|
||||||
|
|
||||||
static InputStream tarFile() {
|
|
||||||
return Resources.class.getResourceAsStream("/untar/test.tar");
|
|
||||||
}
|
|
||||||
|
|
||||||
static InputStream tarGzFile() {
|
|
||||||
return Resources.class.getResourceAsStream("/untar/test.tar.gz");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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 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();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.findFirst()
|
|
||||||
.isPresent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
|
|
||||||
Path destination = Paths.get("/tmp/ant-gz");
|
|
||||||
|
|
||||||
new TarExtractorAnt(Resources.tarGzFile(), true, destination).untar();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.findFirst()
|
|
||||||
.isPresent());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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 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();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.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();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.findFirst()
|
|
||||||
.isPresent());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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 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();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.findFirst()
|
|
||||||
.isPresent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
|
|
||||||
Path destination = Paths.get("/tmp/vfs-gz");
|
|
||||||
|
|
||||||
new TarExtractorVfs(Resources.tarGzFile(), true, destination).untar();
|
|
||||||
|
|
||||||
assertTrue(Files.list(destination)
|
|
||||||
.findFirst()
|
|
||||||
.isPresent());
|
|
||||||
}
|
|
||||||
}
|
|
Binary file not shown.
Binary file not shown.
@ -13,5 +13,4 @@ This module contains articles about Apache Commons libraries.
|
|||||||
- [Apache Commons BeanUtils](https://www.baeldung.com/apache-commons-beanutils)
|
- [Apache Commons BeanUtils](https://www.baeldung.com/apache-commons-beanutils)
|
||||||
- [Histograms with Apache Commons Frequency](https://www.baeldung.com/apache-commons-frequency)
|
- [Histograms with Apache Commons Frequency](https://www.baeldung.com/apache-commons-frequency)
|
||||||
- [An Introduction to Apache Commons Lang 3](https://www.baeldung.com/java-commons-lang-3)
|
- [An Introduction to Apache Commons Lang 3](https://www.baeldung.com/java-commons-lang-3)
|
||||||
- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](https://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library)
|
- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](https://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library)
|
||||||
- More articles: [[next-->]](../libraries-apache-commons-2)
|
|
2
pom.xml
2
pom.xml
@ -872,7 +872,6 @@
|
|||||||
<module>libraries-6</module>
|
<module>libraries-6</module>
|
||||||
|
|
||||||
<module>libraries-apache-commons</module>
|
<module>libraries-apache-commons</module>
|
||||||
<module>libraries-apache-commons-2</module>
|
|
||||||
<module>libraries-apache-commons-collections</module>
|
<module>libraries-apache-commons-collections</module>
|
||||||
<module>libraries-apache-commons-io</module>
|
<module>libraries-apache-commons-io</module>
|
||||||
<module>libraries-data-2</module>
|
<module>libraries-data-2</module>
|
||||||
@ -1135,7 +1134,6 @@
|
|||||||
<module>libraries-5</module>
|
<module>libraries-5</module>
|
||||||
<module>libraries-6</module>
|
<module>libraries-6</module>
|
||||||
<module>libraries-apache-commons</module>
|
<module>libraries-apache-commons</module>
|
||||||
<module>libraries-apache-commons-2</module>
|
|
||||||
<module>libraries-apache-commons-collections</module>
|
<module>libraries-apache-commons-collections</module>
|
||||||
<module>libraries-apache-commons-io</module>
|
<module>libraries-apache-commons-io</module>
|
||||||
<module>libraries-data-2</module>
|
<module>libraries-data-2</module>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user