commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robert moore <robert.mo...@openlogic.com>
Subject VFS FileContent inputStream holding file reference ?
Date Fri, 30 Sep 2005 01:36:52 GMT
hello,

i am having a problem with a file reference being held by the 
FileContent inputStream (or something in vfs, i think) such that after 
accessing the contents of a file (zip in this case) i cannot delete the 
zip file.

here are the details:

i have tested this on commons vfs version 1.0 dev and 1.0 RC4 with the 
same results.

i have a zip file that contains one file entry "rodss-2.2\docs10.txt". 
the file entry is found just fine. but after accessing the entry, i 
cannot delete the zip file.


here is my test code:


public class VFSTest
{
       File pkgFile = new File("c:\\docs.zip");
    public VFSTest()
    {
	   boolean found = loadEntryFromZipFile();
	   if (found)
	   {
System.out.println("found entry in zip, now trying to delete zip");
if (pkgFile.delete())
{
	System.out.println("deleted file");
}
else
{
	System.out.println("could not delete file");
}
	   }
    }


    public boolean loadEntryFromZipFile()
    {
       FileSystemManager fsm;
       ZipFileObject pkgFileEntry = null;
       FileContent fc = null;
       InputStream is = null;
       boolean fileFound = false;
       String fileEntryName = "rodss-2.2\\docs10.txt";

       try
       {
          fsm = VFS.getManager();

          if ( fileEntryName != null && fileEntryName.startsWith( 
"zip:file" ) == false )
          {
             if ( pkgFile == null || pkgFile.exists() == false )
                return false;

             URI uri = pkgFile.toURI();
             String zipString = "zip:" + uri.toString() + "!";
             fileEntryName = zipString + fileEntryName;
          }

          pkgFileEntry = (ZipFileObject) fsm.resolveFile( fileEntryName 
);
          if ( pkgFileEntry != null )
          {
             fc = pkgFileEntry.getContent();
             if ( fc != null )
             {
                is = fc.getInputStream();
                if ( is != null )
                {
                   fileFound = true;
                }
             }
          }
          else
          {
             System.out.println( "file entry does not exist for entry: " 
+ fileEntryName );
          }
       }
       catch ( FileSystemException e )
       {
          fileFound = false;
          System.out.println( "Error accessing file in zip: " + 
e.toString() );
       }
       catch ( Throwable e )
       {
          fileFound = false;
          System.out.println( "Error accessing file in zip: " + 
e.toString() );
       }
       finally
       {
          try
          {

             if (is != null)
	      is.close();

             if ( fc != null )
                fc.close();

             if ( pkgFileEntry != null )
             {
                pkgFileEntry.close();
             }

             is = null;
              fc = null;
              pkgFileEntry = null;
          }
          catch ( Exception e )
          {
             e.printStackTrace();
          }
       }

       return fileFound;

    }

public static void main(String[] args)
{
	new VFSTest();
}
}


sorry about the formatting.

when i run this as is, the zip file will not get deleted. if i comment 
out the lines where i get the inputstream, the file will delete.

does anyone know if there is a bug where the inputstream is not getting 
closed or some other file reference is not cleaned up? or am i doing 
something wrong?

thanks for your help.

robert.


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message