[jboss-cvs] JBossAS SVN: r109907 - projects/vfs/trunk/src/main/java/org/jboss/vfs.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 14 16:04:38 EST 2010


Author: alesj
Date: 2010-12-14 16:04:37 -0500 (Tue, 14 Dec 2010)
New Revision: 109907

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
Log:
[JBVFS-168, JBVFS-169]; add logging to temp handling, fix VF::toURL bug with spaces.


Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java	2010-12-14 19:34:48 UTC (rev 109906)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/TempFileProvider.java	2010-12-14 21:04:37 UTC (rev 109907)
@@ -22,21 +22,25 @@
 
 package org.jboss.vfs;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
-import java.io.Closeable;
+import java.util.Random;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.Random;
 
+import org.jboss.logging.Logger;
+
 /**
  * A provider for temporary physical files and directories.
  *
  * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
  */
 public final class TempFileProvider implements Closeable {
 
+    private static final Logger log = Logger.getLogger(TempFileProvider.class);
     private static final String JBOSS_TMP_DIR_PROPERTY = "jboss.server.temp.dir";
     private static final String JVM_TMP_DIR_PROPERTY = "java.io.tmpdir";
     private static final File TMP_ROOT;
@@ -60,7 +64,7 @@
      * Create a temporary file provider for a given type.
      *
      * @param providerType the provider type string (used as a prefix in the temp file dir name)
-     *
+     * @param executor the executor
      * @return the new provider
      *
      * @throws IOException if an I/O error occurs
@@ -84,7 +88,7 @@
      *
      * @return the temp directory
      *
-     * @throws IOException
+     * @throws IOException for any error
      */
     public TempDir createTempDir(String originalName) throws IOException {
         if (!open.get()) {
@@ -96,9 +100,8 @@
             if (f.mkdir())
                 return new TempDir(this, f);
         }
-        final IOException eo = new IOException(
-                String.format("Could not create directory for original name '%s' after %d attempts", originalName, Integer.valueOf(RETRIES)));
-        throw eo;
+        throw new IOException(
+                String.format("Could not create directory for original name '%s' after %d attempts", originalName, RETRIES));
     }
 
     private static final Random rng = new Random();
@@ -109,12 +112,12 @@
             if (f.mkdir())
                 return f;
         }
-        final IOException eo = new IOException(
+        throw new IOException(
                 String.format("Could not create directory for root '%s' (prefix '%s', suffix '%s') after %d attempts",
                         root,
                         prefix,
-                        suffix));
-        throw eo;
+                        suffix,
+                        RETRIES));
     }
 
     static String createTempName(String prefix, String suffix) {
@@ -143,7 +146,8 @@
         }
 
         public void run() {
-            if (!VFSUtils.recursiveDelete(root)) {
+            if (VFSUtils.recursiveDelete(root) == false) {
+                log.tracef("Failed to delete root (%s), retrying in 30sec.", root);
                 executor.schedule(this, 30L, TimeUnit.SECONDS);
             }
         }

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-12-14 19:34:48 UTC (rev 109906)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFSUtils.java	2010-12-14 21:04:37 UTC (rev 109907)
@@ -21,36 +21,21 @@
 */
 package org.jboss.vfs;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileInputStream;
+import java.io.*;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
+import java.util.jar.Attributes;
 import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
 
 import org.jboss.logging.Logger;
 import org.jboss.util.collection.CollectionsFactory;
@@ -468,7 +453,7 @@
      * one does not exist.
      *
      * @param virtualFile the virtual file to write
-     * @param bytes the bytes
+     * @param is the input stream
      *
      * @throws IOException if an error occurs
      */
@@ -498,7 +483,11 @@
      */
     public static URL getVirtualURL(VirtualFile file) throws MalformedURLException {
         // todo: specify the URL handler directly as a minor optimization
-        return new URL(VFS_PROTOCOL, "", -1, file.getPathName(true));
+        try {
+            return getVirtualURI(file).toURL();
+        } catch (URISyntaxException e) {
+            throw new MalformedURLException(e.getMessage());
+        }
     }
 
     /**



More information about the jboss-cvs-commits mailing list