I would like to create an uncompressed file from a compressed file inside of a tar archive.

Can VFS allow me to do this in one step? I can get the compressed.gz file from archive.tar as a file on disk, then I can decompress the gzip file and then delete the .gz version. If there is an example, tutorial or book online or in print that would be great, I haven't found anything like this yet.

Conceptually there is a tar file:

archive.tar
+- tardir/
    +- content.txt.gz

I'd like to end up with an uncompressed file "content.txt".

I tried something like:

FileObject gzTarFile = fsManager.resolveFile("tar:gz:/archive.tar!/tardir/content.txt.gz");

LocalFile newFile = (LocalFile) fsManager.resolveFile("file:///destination/content.txt");
   newFile.copyFrom(gzTarFile, new AllFileSelector());

Thanks in advance for any advice
-Ken

The test program I'm working with follows:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
package gov.noaa.eds.tryVfs;

import org.apache.commons.vfs.FileName;
import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.FileSystemException;
import org.apache.commons.vfs.FileSystemManager;
import org.apache.commons.vfs.VFS;

/**
* Try using VFS to read the content of a compressed (gz) file inside of
* a tar file.
*/
public class App
{
   static FileSystemManager fsManager = null;
public static void main( String[] args )
   {
       try {
           fsManager = VFS.getManager();
       } catch (FileSystemException ex) {
           ex.printStackTrace();
       }
try {
           /* resolveFile OK */
           System.out.println("Resolve tar file:");
           FileObject tarFile = fsManager.resolveFile(
                   "tar:/extra/data/tryVfs/archive.tar");
FileName tarFileName = tarFile.getName();
           System.out.println("  Path     : " + tarFileName.getPath());
           System.out.println("  URI      : " + tarFileName.getURI());
/* resolveFile OK */
           System.out.println("Resolve gzip file inside tar file:");
           FileObject gzTarFile = fsManager.resolveFile(
"tar:file:///extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz"); FileName gzTarFileName = gzTarFile.getName();
           System.out.println("  Path     : " + gzTarFileName.getPath());
           System.out.println("  URI      : " + gzTarFileName.getURI());
/* resolveFile has an error * uncomment one of the // "file string" arguments for resolveFile below
            * each of the strings I've tried has an /* error message * /
            */
System.out.println("Resolve content of gzip file inside tar file:");
           FileObject contentFile = fsManager.resolveFile(
// "tar:gz:/extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz" /* Unknown message with code "Unknown message with code "vfs.provider.tar/open-tar-file.error".". */ // "tar:gz:///extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz" /* Unknown message with code "Unknown message with code "vfs.provider.tar/open-tar-file.error".". */ // "tar:file:gz:/extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz" /* URI "file:gz:///extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz" is not an absolute file name. */ // "tar:file:gz:/extra/data/tryVfs/archive.tar!///tarDir/content.txt.gz!/content.txt" /* URI "file:gz:///extra/data/tryVfs/archive.tar!/tarDir/content.txt.gz" is not an absolute file name. */ "tar:gz:///extra/data/tryVfs/archive.tar!/tarDir/content.txt" /* Unknown message with code "Unknown message with code "vfs.provider.tar/open-tar-file.error".". */
               );
FileName contentFileName = contentFile.getName();
           System.out.println("  Path     : " + contentFileName.getPath());
           System.out.println("  URI      : " + contentFileName.getURI());
/* copy uncompressed content to a new file */
//            LocalFile newFile = (LocalFile) fsManager.resolveFile(
// "file:///extra/data/tryVfs/content.txt"); // newFile.copyFrom(contentFile, new AllFileSelector());
       } catch (FileSystemException ex) {
           ex.printStackTrace();
       }
   } // main( String[] args )
}

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

Reply via email to