Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 53483 invoked from network); 2 Jun 2005 09:33:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 Jun 2005 09:33:39 -0000 Received: (qmail 78918 invoked by uid 500); 2 Jun 2005 09:33:32 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 78857 invoked by uid 500); 2 Jun 2005 09:33:31 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 78797 invoked by uid 99); 2 Jun 2005 09:33:30 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from sophia.inria.fr (HELO sophia.inria.fr) (138.96.64.20) by apache.org (qpsmtpd/0.28) with ESMTP; Thu, 02 Jun 2005 02:33:28 -0700 Received: from localhost (localhost [127.0.0.1]) by sophia.inria.fr (8.12.11/8.12.9) with ESMTP id j529XCLf012252 for ; Thu, 2 Jun 2005 11:33:12 +0200 Received: from [138.96.66.4] (dahu.inria.fr [138.96.66.4]) by sophia.inria.fr (8.12.11/8.12.9) with ESMTP id j529Wx5s012165 for ; Thu, 2 Jun 2005 11:32:59 +0200 Message-ID: <429ED24B.4050800@sophia.inria.fr> Date: Thu, 02 Jun 2005 11:32:59 +0200 From: Philippe Poulard User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.5) Gecko/20041220 X-Accept-Language: fr-FR,en MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: [VFS] VFS.getManager().getFilesCache() - exists() vs findFiles() References: <20050518225313.30303.qmail@web31512.mail.mud.yahoo.com> <428C2457.9090504@ops.co.at> <428C8D71.3080008@ascii27.net> <428CC1C4.80206@ops.co.at> <429DE963.1050706@sophia.inria.fr> <429DF548.8040706@ops.co.at> In-Reply-To: <429DF548.8040706@ops.co.at> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-1.6 (sophia.inria.fr [138.96.64.20]); Thu, 02 Jun 2005 11:33:00 +0200 (MEST) X-Virus-Scanned: by amavisd-new at sophia.inria.fr X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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