Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Commons Wiki" for 
change notification.

The following page has been changed by KenTanaka:
http://wiki.apache.org/jakarta-commons/ExtractAndDecompressGzipFiles

The comment on the change is:
Noted a more generic approach noted by Mario Ivankovits

------------------------------------------------------------------------------
  The contents of the {{{content.txt}}} and {{{non-gzip.txt}}} files are just a 
directory listings, dump in anything you want here.
  For this example the sample {{{archive.tar}}} is located in the 
{{{/extra/data/tryVfs}}} directory. You can see that hardcoded in the java 
example below. The {{{content.txt}}} and {{{non-gzip.txt}}} files will be 
extracted into the same location.
  
- = Key Concept =
+ = Key Concepts =
+ == Building the resolveFile '''name''' String ==
- An essential ingredient for this "recipe" is the '''name''' argument for the 
{{{FileSystemManager.resolveFile(String name)}}} method. This is present around 
lines defining and using `String gzName`, line numbers 99-100 in the 
ExtractFromGzipInTar.java code listing below. The important work of connecting 
to the content.txt file inside the content.txt.gz file inside the archive.tar 
file is performed by
+ An essential ingredient for this "recipe" is the '''name''' argument for the 
{{{FileSystemManager.resolveFile(String name)}}} method. See this in the lines 
defining and using `String gzName`, line numbers 99-101 in the 
ExtractFromGzipInTar.java code listing below. The important work of connecting 
to the content.txt file inside the content.txt.gz file inside the archive.tar 
file is performed by
  {{{
  FileSystemManager fsManager = VFS.getManager();
  FileObject file = fsManager.resolveFile( 
"gz:tar:file:///extra/data/tryVfs/archive.tar!/tardir/content.txt.gz!content.txt"
 );
@@ -52, +53 @@

  
   
'''gz:'''`tar:file:///extra/data/tryVfs/archive.tar!/tardir/content.txt.gz`''!''__`content.txt`__
  
- 
- 
+ == Generic Drill-down ==
+ On line 90 I'm giving special attention to gzip files
+ {{{
+ if (extractFile.getName().getExtension().equals("gz"))
+ }}}
+ and other types of compression like zip and bzip2 (as well as nested archives 
like jar and tar) will not be expanded. To generically drill down and expand 
zip, bzip2, jar, tar files to arbitrary depth, eliminate the "gz" specific code 
and use instead
+ {{{
+ if (manager.canCreateFileSystem(extractFile))
+ {
+     FileObject innerFile = manager.createFileSystem(extractFile);
+ }
+ }}}
  
  = pom.xml Project file =
  This example uses Maven2. There is a '''{{{pom.xml}}}''' to define the project
@@ -202, +213 @@

                  LocalFile extractFile = (LocalFile) 
this.fsManager.resolveFile(extractName);
                  
                  // if the file is gzipped, decompress it
-                 if (extractFile.getName().getExtension().equals("gz")) {
+ /* line  90 */  if (extractFile.getName().getExtension().equals("gz")) {
                      System.out.println("Decompressing " + extractName);
                      
                      // The uncompressed filename we seek
@@ -212, +223 @@

                      // Build the direct path to the uncompressed content of 
the 
                      // gzip file in the tar file.
                      // 
gz:tar:file:///archive.tar!/tardir/content.txt.gz!content.txt
-                     String gzName = new String("gz:" + fname.getURI() + "!" + 
fileName);
+ /* line 100 */      String gzName = new String("gz:" + fname.getURI() + "!" + 
fileName);
                      FileObject gzFile = this.fsManager.resolveFile(gzName);
                      
                      // The decompressed path we want

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to