commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philippe Poulard <Philippe.Poul...@sophia.inria.fr>
Subject Re: [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles()
Date Thu, 02 Jun 2005 09:32:59 GMT
Mario Ivankovits wrote:
> Philippe Poulard wrote:
> 
>> -delete()
>> -copy()
>> -set-attributes()
>>
>> I catch an exception telling me that the file didn't exist ; but it 
>> does exist : i just have create it !!! so, after creation, the cache 
>> seems not be updated
> 
> Could you please pack these steps in a runnable java code. With some 
> asserts which show the problem.
> I will have a look at it then.
> 
> Thanks!
> Mario
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 

FileObject target = XFile.getXFile( 
"xmldb:xyl://user:pwd@www.foo.com/path/to/file.xml" );
target.getContent().setAttribute( "xmldb-resource-type", "XMLResource" );
target.getContent().setAttribute( "cluster", "Raweb2004" );
target.delete();
FileObject src = XFile.getXFile( "file:///path/to/file.xml" );
target.copyFrom( src, Selectors.SELECT_ALL );

this last line throws an exception (see below)

Caused by: org.apache.commons.vfs.FileSystemException: Could not get 
attributes "{1}" because it does not exist.

in the implementation of my XMLDBFileObject (returned with the scheme 
"xmldb"), I have :

     protected OutputStream doGetOutputStream( boolean append ) throws 
FileSystemException {
         return new ByteArrayOutputStream( 1024 ) {
             public void close() throws IOException {
                 try {
                     super.close();
                     byte[] content = toByteArray();
                     Resource resource = getResource();
                     resource.setContent( content );
                     resource.getParentCollection().storeResource( 
resource );
                 } catch ( XMLDBException xdbe ) {
                     throw new FileSystemException( xdbe );
                 }
             }
         };
     }
     Resource getResource() throws FileSystemException, XMLDBException {
         boolean isXML = true;
         Collection coll = DatabaseManager.getCollection(
             XMLDBFileObject.this.getParent().getName().getURI()
         );
         for ( Iterator it = 
XMLDBFileObject.this.getContent().getAttributes().entrySet().iterator() 
; it.hasNext() ; ) {
             /*
              * getAttributes() fails here because the type
              * is FileType.IMAGINARY : it has been set when
              * delete() has been called
              * all the stuff works if i end the doDelete()
              * with close()
              * If target.delete() is not called, the type
              * is not FileType.IMAGINARY and attributes
              * can be used and it works
              */
         );
         Resource resource = coll.createResource(
             XMLDBFileObject.this.getName().getBaseName(),
             isXML ? XML_RESOURCE_TYPE : BINARY_RESOURCE_TYPE
         );
         return resource;
     }


Exception in thread "main" org.apache.commons.vfs.FileSystemException: 
Could not copy "file:///path/to/file.xml" to 
"xmldb:xyl://user:pwd@www.foo.com/path/to/file.xml".
	at org.inria.reflex.modules.io.XFile.copyFrom(XFile.java:884)
	at Test.main(Test.java:122)
Caused by: org.apache.commons.vfs.FileSystemException: Could not close 
the output stream for file 
"xmldb:xyl://user:pwd@www.foo.com/path/to/file.xml".
	at 
org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:504)
	at org.apache.commons.vfs.FileUtil.copyContent(FileUtil.java:106)
	at org.inria.reflex.modules.io.XFile.copyFrom(XFile.java:879)
	... 1 more
Caused by: org.apache.commons.vfs.FileSystemException: Could not get 
attributes "{1}" because it does not exist.
	at 
org.apache.commons.vfs.provider.DefaultFileContent.getAttributes(DefaultFileContent.java:172)
	at 
org.inria.reflex.modules.io.xmldb.XMLDBFileObject.getResource(XMLDBFileObject.java:251)
	at 
org.inria.reflex.modules.io.xmldb.XMLDBFileObject$2.close(XMLDBFileObject.java:217)
	at java.io.FilterOutputStream.close(FilterOutputStream.java:143)
	at 
org.apache.commons.vfs.util.MonitorOutputStream.close(MonitorOutputStream.java:52)
	at 
org.apache.commons.vfs.provider.DefaultFileContent$FileContentOutputStream.close(DefaultFileContent.java:500)
	... 3 more

in fact, as the delete() method cause the problem because it sets the 
type to FileType.IMAGINARY, we can't rely on the file type when copying 
a content file, because as the target will have content, it is obvious 
that its file type must be switched automatically from 
FileType.IMAGINARY to FileType.FILE

(i hope that FOLDERs don't intend to have content ? in this case, there 
should be something that denotes that hasAttributes() return true)

maybe it should be correct in FileUtil :

     /**
      * Copies the content from a source file to a destination file.
      */
     public static void copyContent(final FileObject srcFile,
                                    final FileObject destFile)
         throws IOException
     {
         // the destfile may be imaginary, so, let's correct this 
because we are sure it is a file, now, because we are copying content inside
         destFile.setType( FileType.FILE );

         // Create the output stream via getContent(), to pick up the
         // validation it does
         final OutputStream outstr = 
destFile.getContent().getOutputStream();
         try
         {
             writeContent(srcFile, outstr);
         }
         finally
         {
             outstr.close();
         }
     }

-- 
Cordialement,

            ///
           (. .)
  -----ooO--(_)--Ooo-----
|   Philippe Poulard    |
  -----------------------

---------------------------------------------------------------------
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