commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albretch Mueller (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (COMPRESS-137) 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);
Date Mon, 27 Jun 2011 17:08:48 GMT

    [ https://issues.apache.org/jira/browse/COMPRESS-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13055662#comment-13055662
] 

Albretch Mueller commented on COMPRESS-137:
-------------------------------------------

 Let me add that my goal (as explained in user@commons.apache.org: [compress] trying to feed
data from tar.gz and tar.bz2 files directly to an XMLReader ...) is being able to do something
like this:
~ 
  BufferedReader BfrRdr = null;
  XMLReader XMLRdr = null;
  FileInputStream FIS = null;
  ZipInputStream ZIS = null;
  ZipFile ZFl = null;
  int OPEN_READ = 0x1;
  ZipEntry ZEntry;
// __ 

  try{
   SAXParserFactory SAXFctry = SAXParserFactory.newInstance();
   SAXFctry.setValidating(false); // stop standard validation to allow custom schema
   SAXFctry.setNamespaceAware(true);

   SchemaFactory SchmFctry = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
   SAXFctry.setSchema(SchmFctry.newSchema(new Source[] {new StreamSource(aIXSDFl)}));
   SAXParser SAXPrsr = SAXFctry.newSAXParser();

// __ Create and register the content handler
   XMLRdr = SAXPrsr.getXMLReader();
   XMLRdr.setContentHandler(new DefaultHandler2());

// __ 
   File IZFl = new File(aIXMLFl);
   ZFl = new ZipFile(IZFl, OPEN_READ);
// __ 
   Enumeration<? extends ZipEntry> ZENum = ZFl.entries();
   while(ZENum.hasMoreElements()){
    ZEntry = (ZipEntry)ZENum.nextElement();
    System.out.println("// __ XML Scanning: |" + ZEntry.getName() + "|");
    InputStream IS = ZFl.getInputStream(ZEntry);
    BfrRdr = new BufferedReader(new InputStreamReader(IS, "UTF-8"));
// __ 
    XMLRdr.parse(new InputSource(BfrRdr)); // XMLReader is directly fed the InputStream from
the zip file
// __ 
    IS.close();
   }
// __ 
  }catch(FileNotFoundException FNFX){ FNFX.printStackTrace(System.err); }
    catch(IOException IOX){ IOX.printStackTrace(System.err); }
   catch(ParserConfigurationException PrsConfX){ PrsConfX.printStackTrace(System.err); }
    catch(SAXException SAXX){ SAXX.printStackTrace(System.err); }


> 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

        

Mime
View raw message