commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject svn commit: r192990 - in /jakarta/commons/proper/vfs/trunk/src: java/org/apache/commons/vfs/ java/org/apache/commons/vfs/impl/ java/org/apache/commons/vfs/provider/ java/org/apache/commons/vfs/provider/webdav/ test/org/apache/commons/vfs/provider/webda...
Date Wed, 22 Jun 2005 19:59:44 GMT
Author: imario
Date: Wed Jun 22 12:59:43 2005
New Revision: 192990

URL: http://svn.apache.org/viewcvs?rev=192990&view=rev
Log:
*) minor javadoc fixes
*) make file numbering in DefaultFileReplicator thread safe
*) PR35285: use temporary file instead of in memory byte array as buffer for file write operation
in webdav provider
Submitted By: Torsten Curdt <tcurdt -at- apache.org>
Slightly modified to use VFS's own temporary file handling and reread the webdav resource
state to keep in sync with reality after write

Modified:
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
    jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
    jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/webdav/test/WebdavProviderTestCase.java

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/FileSystemManager.java
Wed Jun 22 12:59:43 2005
@@ -251,5 +251,10 @@
      */
     public FileSystemConfigBuilder getFileSystemConfigBuilder(final String scheme) throws
FileSystemException;
 
+    /**
+     * Resolve the uri to a filename
+     *
+     * @throws FileSystemException if this is not possible
+     */
     public FileName resolveURI(String uri) throws FileSystemException;
 }

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileReplicator.java
Wed Jun 22 12:59:43 2005
@@ -117,7 +117,10 @@
     {
         // Create a unique-ish file name
         final String basename = createFilename(baseName);
-        filecount++;
+        synchronized(this)
+        {
+            filecount++;
+        }
         final File file = createFile(tempDir, basename);
 
         // Keep track to delete later

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/impl/DefaultFileSystemManager.java
Wed Jun 22 12:59:43 2005
@@ -609,6 +609,11 @@
         return ((AbstractFileName) base).createName(resolvedPath);
     }
 
+    /**
+     * resolve the uri to a filename
+     * 
+     * @throws FileSystemException
+     */
     public FileName resolveURI(String uri) throws FileSystemException
     {
         UriParser.checkUriEncoding(uri);

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
Wed Jun 22 12:59:43 2005
@@ -404,6 +404,7 @@
     {
         this.getThreadData().setOutstr(null);
         // setState(STATE_CLOSED);
+
         file.endOutput();
     }
 
@@ -457,7 +458,14 @@
          */
         protected void onClose() throws IOException
         {
-            endInput(this);
+            try
+            {
+                super.onClose();
+            }
+            finally
+            {
+                endInput(this);
+            }
         }
     }
 
@@ -476,7 +484,14 @@
          */
         protected void onClose() throws IOException
         {
-            endRandomAccess();
+            try
+            {
+                super.onClose();
+            }
+            finally
+            {
+                endRandomAccess();
+            }
         }
     }
 
@@ -512,11 +527,18 @@
         {
             try
             {
-                endOutput();
+                super.onClose();
             }
-            catch (final Exception e)
+            finally
             {
-                throw new FileSystemException("vfs.provider/close-outstr.error", file, e);
+                try
+                {
+                    endOutput();
+                }
+                catch (Exception e)
+                {
+                    throw new FileSystemException("vfs.provider/close-outstr.error", file,
e);
+                }
             }
         }
     }

Modified: jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
Wed Jun 22 12:59:43 2005
@@ -33,7 +33,6 @@
 import org.apache.webdav.lib.methods.XMLResponseMethodBase;
 import org.apache.webdav.lib.properties.ResourceTypeProperty;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -62,6 +61,9 @@
     private Set allowedMethods = null;
     // private HttpURL url;
 
+    private static volatile int tmpFileCount = 0;
+    private static final Object tmpFileCountSync = new Object();
+
     protected WebdavFileObject(final GenericFileName name,
                                final WebDavFileSystem fileSystem)
     {
@@ -106,7 +108,6 @@
 
         final URLFileName name = (URLFileName) getName();
 
-        // System.err.println("set on " + System.identityHashCode(this) + " " + getName()
+ ":" + bCheckExists);
         if (resource == null)
         {
             // HttpURL url = new HttpURL(name.getHostName(), name.getPort(), name.getPath());
@@ -134,10 +135,8 @@
                 {
                     setAllowedMethods(null);
 
-                    // System.err.println("process on " + System.identityHashCode(this));
                     // permission denied on this object, but we might get some informations
from the parent
                     processParentDavResource();
-                    // System.err.println("leave on " + System.identityHashCode(this));
                     return;
                 }
                 else
@@ -190,7 +189,6 @@
         }
     }
 
-
     private void setAllowedMethods(Enumeration allowedMethods)
     {
         this.allowedMethods = new TreeSet();
@@ -239,7 +237,6 @@
         WebdavFileObject parent = (WebdavFileObject) getParent();
         try
         {
-            // System.err.println("tell him:" + parent.toString());
             // after this our resource should be reset
             parent.doListChildrenResolved();
         }
@@ -341,7 +338,7 @@
         }
 
         // reread allowed methods
-        allowedMethods = null;
+        reattach();
     }
 
     /**
@@ -358,7 +355,7 @@
         }
 
         // reread allowed methods
-        allowedMethods = null;
+        reattach();
     }
 
     /**
@@ -369,7 +366,6 @@
         // final GenericFileName name = (GenericFileName) newfile.getName();
         // HttpURL url = new HttpURL(name.getUserName(), name.getPassword(), name.getHostName(),
name.getPort(), newfile.getName().getPath());
         // String uri = url.getURI();
-        // System.err.println(resource.getHttpURL().getPath());
 
         final boolean ok = resource.moveMethod(newfile.getName().getPath());
         if (!ok)
@@ -378,7 +374,7 @@
         }
 
         // reread allowed methods
-        allowedMethods = null;
+        reattach();
     }
 
     /**
@@ -394,7 +390,15 @@
      */
     protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
     {
-        return new WebdavOutputStream();
+        int fileCount;
+        FileObject webdavTmp;
+        synchronized(tmpFileCountSync)
+        {
+            tmpFileCount++;
+            fileCount = tmpFileCount;
+        }
+        webdavTmp = getFileSystem().getFileSystemManager().resolveFile("tmp://webdav_tmp.c"
+ fileCount);
+        return new WebdavOutputStream(webdavTmp);
     }
 
     /**
@@ -408,14 +412,17 @@
     /**
      * An OutputStream that writes to a Webdav resource.
      *
-     * @todo Don't gather up the body in a ByteArrayOutputStream; need to write directly
to connection
+     * @todo Use piped stream to avoid temporary file
      */
     private class WebdavOutputStream
         extends MonitorOutputStream
     {
-        public WebdavOutputStream()
+        private final FileObject webdavTmp;
+
+        public WebdavOutputStream(FileObject webdavTmp) throws FileSystemException
         {
-            super(new ByteArrayOutputStream());
+            super(webdavTmp.getContent().getOutputStream());
+            this.webdavTmp = webdavTmp;
         }
 
         /**
@@ -423,19 +430,50 @@
          */
         protected void onClose() throws IOException
         {
-            final ByteArrayOutputStream outstr = (ByteArrayOutputStream) out;
+            // final ByteArrayOutputStream outstr = (ByteArrayOutputStream) out;
 
             // Adjust the resource path (this file object may have been a folder)
-            //// resource.getHttpURL().setEscapedPath(getName().getPath());
             resource.getHttpURL().setPath(getName().getPathDecoded());
-            final boolean ok = resource.putMethod(outstr.toByteArray());
-            if (!ok)
+            // final boolean ok = resource.putMethod(outstr.toByteArray());
+            try
             {
-                throw new FileSystemException("vfs.provider.webdav/write-file.error", resource.getStatusMessage());
+                final boolean ok = resource.putMethod(webdavTmp.getContent().getInputStream());
+                if (!ok)
+                {
+                    throw new FileSystemException("vfs.provider.webdav/write-file.error",
resource.getStatusMessage());
+                }
+            }
+            finally
+            {
+                // close and delete the temporary file
+                webdavTmp.close();
+                webdavTmp.delete();
             }
+        }
+    }
 
-            // reread allowed methods
-            allowedMethods = null;
+    protected void handleCreate(final FileType newType) throws Exception
+    {
+        // imario@apache.org: this is to reread the webdav internal state
+        // Ill treat this as workaround
+        reattach();
+        super.handleCreate(newType);
+    }
+
+    /**
+     * refresh the webdav internals
+     * @throws FileSystemException
+     */
+    private void reattach() throws FileSystemException
+    {
+        try
+        {
+            doDetach();
+            doAttach();
+        }
+        catch (Exception e)
+        {
+            throw new FileSystemException(e);
         }
     }
 
@@ -478,7 +516,7 @@
     {
         // Again to be IIS compatible
         // return hasAllowedMethods("POST");
-        return hasAllowedMethods("COPY");
+        return hasAllowedMethods("DELETE");
     }
 
     private void getAllowedMethods() throws IOException

Modified: jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/webdav/test/WebdavProviderTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/webdav/test/WebdavProviderTestCase.java?rev=192990&r1=192989&r2=192990&view=diff
==============================================================================
--- jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/webdav/test/WebdavProviderTestCase.java
(original)
+++ jakarta/commons/proper/vfs/trunk/src/test/org/apache/commons/vfs/provider/webdav/test/WebdavProviderTestCase.java
Wed Jun 22 12:59:43 2005
@@ -20,6 +20,7 @@
 import org.apache.commons.vfs.FileSystemManager;
 import org.apache.commons.vfs.impl.DefaultFileSystemManager;
 import org.apache.commons.vfs.provider.webdav.WebdavFileProvider;
+import org.apache.commons.vfs.provider.temp.TemporaryFileProvider;
 import org.apache.commons.vfs.test.AbstractProviderTestConfig;
 import org.apache.commons.vfs.test.ProviderTestSuite;
 
@@ -44,6 +45,7 @@
         throws Exception
     {
         manager.addProvider("webdav", new WebdavFileProvider());
+        manager.addProvider("tmp", new TemporaryFileProvider());
     }
 
     /**



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


Mime
View raw message