...
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
An essential ingredient for this "recipe" is the name argument for the FileSystemManager.resolveFile(String name)
method. This is present around lines 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
No Format |
---|
FileSystemManager fsManager = VFS.getManager();
FileObject file = fsManager.resolveFile( "gz:tar:file:///extra/data/tryVfs/archive.tar!/tardir/content.txt.gz!content.txt" );
|
In order to build similar strings for your own purposes, you will need to understand what is going on here. The paths to the file of interest are chained together with the "!" character as a separator. At the same time the corresponding file system scheme designators ("file:", "tar:" and "gz:") should be prepended onto the front in reverse order. Taking this one step at a time, we have the full path to the archive.tar
file (/extra/data/tryVfs/archive.tar), which is accessed through the normal file system *file:*
*file:*+///extra/data/tryVfs/archive.tar+
Now we will treat the file as a tar: file and inside this archive we will append a "!" and navigate to /tardir/content.txt.gz
.
tar:file:///extra/data/tryVfs/archive.tar
!/tardir/content.txt.gz
Finally we will use the gz: file system to read the uncompressed content.txt
(again using the "!" separator character)
gz:tar:file:///extra/data/tryVfs/archive.tar!/tardir/content.txt.gz
!content.txt
pom.xml Project file
This example uses Maven2. There is a pom.xml
to define the project
...