Description
public static void deGzipArchive(String filepath,String dir) throws Exception { final File input = new File(filepath); final InputStream is = new FileInputStream(input); final CompressorInputStream in = new GzipCompressorInputStream(is, true); TarArchiveInputStream tin = new TarArchiveInputStream(in); TarArchiveEntry entry = tin.getNextTarEntry(); while (entry != null) { File archiveEntry = new File(dir, entry.getName()); archiveEntry.getParentFile().mkdirs(); if (entry.isDirectory()) { archiveEntry.mkdir(); entry = tin.getNextTarEntry(); continue; } OutputStream out = new FileOutputStream(archiveEntry); IOUtils.copy(tin, out); out.close(); entry = tin.getNextTarEntry(); } in.close(); tin.close(); } public static void main(String[] args) throws Exception { Gztest.deGzipArchive("D:/20000102.0000+0800-20000102.0015+0800_0.tar.gz","D:/"); }
the tar.gz file can be decompressed in linux environment use 'tar' command.
The error log:
Exception in thread "main" java.io.IOException: Error detected parsing the header
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:286)
at gztest.deGzipArchive(gztest.java:23)
at gztest.main(gztest.java:149)
Caused by: java.lang.IllegalArgumentException: Invalid byte 100 at offset 0 in 'dos
' len=8
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctal(TarUtils.java:141)
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctalOrBinary(TarUtils.java:171)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1128)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:1091)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.<init>(TarArchiveEntry.java:368)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:284)
... 2 more