Permalink
Browse files

[JBVFS-168, JBVFS-169]; add logging to temp handling, fix VF::toURL b…

…ug with spaces.
  • Loading branch information...
alesj committed Dec 14, 2010
1 parent e17b494 commit 99982b5ed3bfa6633e558236197a284c82963297
Showing with 26 additions and 33 deletions.
  1. +15 −11 src/main/java/org/jboss/vfs/TempFileProvider.java
  2. +11 −22 src/main/java/org/jboss/vfs/VFSUtils.java
@@ -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@redhat.com">David M. Lloyd</a>
+ * @author <a href="mailto:ales.justin@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 @@ private TempFileProvider(File providerRoot, ScheduledExecutorService executor) {
*
* @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 @@ public TempDir createTempDir(String originalName) throws IOException {
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 @@ private static File createTempDir(String prefix, String suffix, File root) throw
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 DeleteTask(File root) {
}
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);
}
}
@@ -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 @@ public static void writeFile(VirtualFile virtualFile, byte[] bytes) throws IOExc
* 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 void writeFile(VirtualFile virtualFile, InputStream is) throws IOE
*/
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());
+ }
}
/**

0 comments on commit 99982b5

Please sign in to comment.