Question

I am working on a project where I have to extract a .gz which has a log file in text format inside. I am trying this code:

public void extractFile(String sourceFilePath) {
    // Untar....

    System.out.println("\n\nextracting file ............... ");

    File sourceFile = new File(sourceFilePath);

    //create the directory to download
    createFile("/home/myname/workspace/log-monitor/target/classes/extractDir");

    File destDir = new File("/home/myname/workspace/log-monitor/target/classes/extractDir");

    Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);
    try {
        archiver.extract(sourceFile, destDir);
    } catch (IOException ex) {
        // TODO Auto-generated catch block
        ex.printStackTrace();
    }

}

And I am getting error :

java.io.IOException: org.apache.commons.compress.archivers.ArchiveException: No Archiver found for the stream signature

imported :

 import org.rauschig.jarchivelib.*;

And added this in POM:

<dependency>
<groupId>org.rauschig</groupId>
<artifactId>jarchivelib</artifactId>
<version>0.3.0</version>
</dependency>

Mine is CentOS OS. And using jdk1.7.

For more information I tried:

 Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP);

 ArchiverFactory.createArchiver("gz");

None of them Worked.

Can any one help. I am sure it is about formatting but not sure what to for .gz file.

Thanks in advance.

Was it helpful?

Solution

Maybe this will help:

File a = new File("data/readme.txt.gz");
File o = new File("data/");
Compressor compressor = CompressorFactory.createCompressor(a);
try {
    compressor.decompress(a, o);
} catch (IOException ex) {
    ex.printStackTrace();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top