[
https://issues.apache.org/jira/browse/COMPRESS-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13056213#comment-13056213
]
Torsten Curdt commented on COMPRESS-137:
----------------------------------------
As demonstrated in
https://svn.apache.org/repos/asf/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/ChainingTestCase.java
chaining works just fine.
You misunderstood the meaning of "getFile" (TBH I think that method should not
exist at all) and are using the API the wrong way. Compress uses the same
approach as the standard JDK classes.
In your case this means you need to find your ArchiveEntry and then the
InputStream is positioned right where you need it. Search for
"testTarUnarchive" to see an example.
> TarArchiveEntry.getFile() always returns null + no way to get an InputStream
> from TarArchiveInputStream similar to what you do with
> (java.util.zip.ZipFile())..getInputStream(ZipEntry);
> ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: COMPRESS-137
> URL: https://issues.apache.org/jira/browse/COMPRESS-137
> Project: Commons Compress
> Issue Type: Bug
> Components: Compressors
> Affects Versions: 1.1
> Environment: $ uname -a
> Linux Microknoppix 2.6.31.6 #4 SMP PREEMPT Tue Nov 10 19:11:11 CET 2009 i686
> GNU/Linux
> $ java -version
> java version "1.6.0_16"
> Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
> Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
> $ echo $CLASSPATH
> /media/sdb3/prjx/Java/JUtils:/media/sdb3/prjx/Java/JUtils/jars/commons-compress-1.1.jar:.
> Reporter: Albretch Mueller
> Priority: Critical
> Labels: zip_through_XMLReader
> Fix For: 1.1
>
>
> ~
> this is a test run using httpd-2.2.19.tar[.gz,bz2] to show what I mean
> ~
> lbrtchx
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> ~ ~ ~
> $ wget http://apache.cyberuse.com//httpd/httpd-2.2.19.tar.gz
> --2011-06-27 11:21:46-- http://apache.cyberuse.com//httpd/httpd-2.2.19.tar.gz
> Resolving apache.cyberuse.com... 174.132.149.89
> Connecting to apache.cyberuse.com|174.132.149.89|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 7113418 (6.8M) [application/x-gzip]
> Saving to: `httpd-2.2.19.tar.gz'
> 100%[===...===>] 7,113,418 296K/s in 24s
> 2011-06-27 11:22:10 (285 KB/s) - `httpd-2.2.19.tar.gz' saved [7113418/7113418]
> $ wget http://apache.cyberuse.com//httpd/httpd-2.2.19.tar.bz2
> --2011-06-27 11:22:19--
> http://apache.cyberuse.com//httpd/httpd-2.2.19.tar.bz2
> Resolving apache.cyberuse.com... 174.132.149.89
> Connecting to apache.cyberuse.com|174.132.149.89|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 5322082 (5.1M) [application/x-bzip2]
> Saving to: `httpd-2.2.19.tar.bz2'
> 100%[===...===>] 5,322,082 256K/s in 25s
> 2011-06-27 11:22:44 (207 KB/s) - `httpd-2.2.19.tar.bz2' saved
> [5322082/5322082]
> $ wget http://www.apache.org/dist/httpd/httpd-2.2.19.tar.gz.md5
> --2011-06-27 11:22:51--
> http://www.apache.org/dist/httpd/httpd-2.2.19.tar.gz.md5
> Resolving www.apache.org... 140.211.11.131
> Connecting to www.apache.org|140.211.11.131|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 54 [text/plain]
> Saving to: `httpd-2.2.19.tar.gz.md5'
> 100%[===...===>] 54 --.-K/s in 0s
> 2011-06-27 11:22:51 (4.23 MB/s) - `httpd-2.2.19.tar.gz.md5' saved [54/54]
> $ wget http://www.apache.org/dist/httpd/httpd-2.2.19.tar.bz2.md5
> --2011-06-27 11:23:02--
> http://www.apache.org/dist/httpd/httpd-2.2.19.tar.bz2.md5
> Resolving www.apache.org... 140.211.11.131
> Connecting to www.apache.org|140.211.11.131|:80... connected.
> HTTP request sent, awaiting response... 200 OK
> Length: 55 [text/plain]
> Saving to: `httpd-2.2.19.tar.bz2.md5'
> 100%[===...===>] 55 --.-K/s in 0s
> 2011-06-27 11:23:02 (4.91 MB/s) - `httpd-2.2.19.tar.bz2.md5' saved [55/55]
> $ ls -l httpd-2.2.19.tar.*
> -rw-r--r-- 1 knoppix knoppix 5322082 May 21 18:58 httpd-2.2.19.tar.bz2
> -rw-r--r-- 1 knoppix knoppix 55 May 21 18:58 httpd-2.2.19.tar.bz2.md5
> -rw-r--r-- 1 knoppix knoppix 7113418 May 21 18:58 httpd-2.2.19.tar.gz
> -rw-r--r-- 1 knoppix knoppix 54 May 21 18:58 httpd-2.2.19.tar.gz.md5
> $ md5sum -b httpd-2.2.19.tar.bz2
> 832f96a6ec4b8fc7cf49b9efd4e89060 *httpd-2.2.19.tar.bz2
> $ md5sum -b httpd-2.2.19.tar.gz
> e9f5453e1e4d7aeb0e7ec7184c6784b5 *httpd-2.2.19.tar.gz
> $ cat *.md5
> 832f96a6ec4b8fc7cf49b9efd4e89060 *httpd-2.2.19.tar.bz2
> e9f5453e1e4d7aeb0e7ec7184c6784b5 *httpd-2.2.19.tar.gz
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> ~ ~ ~
> /*
> TarArchiveEntry.getFile() always returns null + no way to get an InputStream
> from TarArchiveInputStream similar to what you do with
> (java.util.zip.ZipFile())..getInputStream(ZipEntry);
> */
> import org.apache.commons.compress.compressors.bzip2.*;
> import org.apache.commons.compress.compressors.gzip.*;
> import org.apache.commons.compress.archivers.tar.*;
> import org.apache.commons.compress.utils.*;
> import org.apache.commons.compress.archivers.*;
> import java.io.*;
> import java.util.*;
> import java.text.*;
> // __
> public class TAR00Test{
> // __
> public static void main(String[] args){
> // __
> TarArchiveInputStream TArkIS = null;
> TarArchiveEntry TArkEntry = null;
> File TARFl, IFl, IDir = new
> File("/media/sda1/prjx/sw/text_synch/XML_Fls/test");
> String[] aIFl = new String[]{"httpd-2.2.19.tar.bz2", "httpd-2.2.19.tar.gz"};
> String aFlPth;
> // __
> try{
> for(int i = 0; (i < aIFl.length); ++i){
> IFl = new File(IDir, aIFl[i]);
> aFlPth = IFl.getCanonicalPath();
> if(IFl.exists()){
> aFlPth = aFlPth.toLowerCase();
> // __
> if(aFlPth.endsWith(".tar.bz2")){
> TArkIS = new TarArchiveInputStream(new BZip2CompressorInputStream(new
> FileInputStream(IFl)));
> }
> else if(aFlPth.endsWith(".tar.gz")){
> TArkIS = new TarArchiveInputStream(new GzipCompressorInputStream(new
> FileInputStream(IFl)));
> }
> else{} // ...
> // __
> TArkEntry = (TarArchiveEntry)TArkIS.getNextEntry();
> while(TArkEntry != null){
> if(!TArkEntry.isDirectory()){
> System.err.println(TArkEntry);
> // __ org/apache/commons/compress/archivers/tar/TarArchiveEntry.html
> System.err.println("// __ getName: |" + TArkEntry.getName() + "|");
> System.err.println("// __ getSize: |" + TArkEntry.getSize() + "|");
> System.err.println("// __ getUserId: |" + TArkEntry.getUserId() + "|");
> System.err.println("// __ GroupId: |" + TArkEntry.getGroupId() + "|");
> System.err.println("// __ GroupName: |" + TArkEntry.getGroupName() +
> "|");
> System.err.println("// __ LastModifiedDate: |" +
> TArkEntry.getLastModifiedDate() + "|");
> System.err.println("// __ LinkName: |" + TArkEntry.getLinkName() +
> "|");
> System.err.println("// __ Mode: |" + TArkEntry.getMode() + "|");
> System.err.println("// __ ModTime: |" + TArkEntry.getModTime() + "|");
> TARFl = TArkEntry.getFile();
> System.err.println("// __ File: |" + TARFl + "|");
> if(TARFl != null){ System.err.println("~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ *
> ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~ * ~"); }
> else{ System.err.println("~"); }
> }
> TArkEntry = (TarArchiveEntry)TArkIS.getNextEntry();
> }
> // __
> TArkIS.close();
> }// (IFl.exists())
> else{ System.err.println("// __ File not found! |" + aFlPth + "|"); }
> }// i [0, aIFl.length)
> }catch(FileNotFoundException FlNFX){ FlNFX.printStackTrace(System.err); }
> catch(IOException IOX){ IOX.printStackTrace(System.err); }
> }
> }
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira