[jboss-cvs] JBossAS SVN: r91910 - in projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual: spi and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Aug 1 13:03:43 EDT 2009
Author: jason.greene at jboss.com
Date: 2009-08-01 13:03:43 -0400 (Sat, 01 Aug 2009)
New Revision: 91910
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java
Log:
Ensure that URL paths for directories always end in '/'
Add special support to JavaZipFileSystem for streaming the backing zip when it is mounted
Also returns the backing zip size when it is mounted
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-08-01 15:44:54 UTC (rev 91909)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java 2009-08-01 17:03:43 UTC (rev 91910)
@@ -55,10 +55,10 @@
/**
* Virtual File System
- *
+ *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision: 1.1 $
*/
public class VFS
@@ -136,7 +136,7 @@
/**
* Get file.
* Backcompatibility method.
- *
+ *
* @param uri the uri
* @return the file matching uri
* @throws IOException if there is a problem accessing the VFS
@@ -149,11 +149,14 @@
}
/**
- * Initialize VFS protocol handlers package property.
+ * Initialize VFS protocol handlers package property.
*/
@SuppressWarnings({"deprecation", "unchecked"})
public static void init()
{
+ // A small hack that allows us to replace file for now
+ URL.setURLStreamHandlerFactory(null);
+
String pkgs = System.getProperty("java.protocol.handler.pkgs");
if (pkgs == null || pkgs.trim().length() == 0)
{
@@ -256,7 +259,7 @@
/**
* Get the children
- *
+ *
* @return the children
* @throws IOException for any problem accessing the virtual file system
*/
@@ -267,7 +270,7 @@
/**
* Get the children
- *
+ *
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
@@ -276,12 +279,12 @@
{
return getRootVirtualFile().getChildren(filter);
}
-
+
/**
* Get all the children recursively<p>
- *
+ *
* This always uses {@link VisitorAttributes#RECURSE}
- *
+ *
* @return the children
* @throws IOException for any problem accessing the virtual file system
*/
@@ -289,12 +292,12 @@
{
return getRootVirtualFile().getChildrenRecursively(null);
}
-
+
/**
* Get all the children recursively<p>
- *
+ *
* This always uses {@link VisitorAttributes#RECURSE}
- *
+ *
* @param filter to filter the children
* @return the children
* @throws IOException for any problem accessing the virtual file system
@@ -303,10 +306,10 @@
{
return getRootVirtualFile().getChildrenRecursively(filter);
}
-
+
/**
* Visit the virtual file system from the root
- *
+ *
* @param visitor the visitor
* @throws IOException for any problem accessing the VFS
* @throws IllegalArgumentException if the visitor is null
@@ -318,7 +321,7 @@
/**
* Visit the virtual file system
- *
+ *
* @param file the file
* @param visitor the visitor
* @throws IOException for any problem accessing the VFS
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java 2009-08-01 15:44:54 UTC (rev 91909)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java 2009-08-01 17:03:43 UTC (rev 91910)
@@ -64,7 +64,7 @@
* Constant representing the URL file protocol
*/
public static final String FILE_PROTOCOL = "file";
-
+
/** Standard separator for JAR URL */
public static final String JAR_URL_SEPARATOR = "!/";
@@ -124,7 +124,7 @@
throw new IllegalArgumentException("Null paths");
boolean trace = log.isTraceEnabled();
-
+
Manifest manifest = getManifest(file);
if (manifest == null)
return;
@@ -148,7 +148,7 @@
if (trace)
log.trace("Parsing Class-Path: " + classPath + " for " + file.getName() + " parent=" + parent.getName());
-
+
StringTokenizer tokenizer = new StringTokenizer(classPath);
while (tokenizer.hasMoreTokens())
{
@@ -465,7 +465,7 @@
public static URL getVirtualURL(VirtualFile file) throws MalformedURLException
{
// todo: specify the URL handler directly as a minor optimization
- return new URL("file", "", -1, file.getPathName());
+ return new URL("file", "", -1, file.getPathName(true));
}
/**
@@ -477,7 +477,7 @@
*/
public static URI getVirtualURI(VirtualFile file) throws URISyntaxException
{
- return new URI("file", "", file.getPathName(), null);
+ return new URI("file", "", file.getPathName(true), null);
}
/**
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-08-01 15:44:54 UTC (rev 91909)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VirtualFile.java 2009-08-01 17:03:43 UTC (rev 91910)
@@ -91,10 +91,22 @@
/**
* Get the absolute VFS full path name (/xxx/yyy/foo.ear/baz.jar/org/jboss/X.java)
*
- * @return the VFS relative path name
+ * @return the VFS full path name
*/
public String getPathName()
{
+ return getPathName(false);
+ }
+
+ /**
+ * Get the absolute VFS full path name. If this is a URL then directory entries will
+ * have a trailing slash.
+ *
+ * @param url whether or not this path is being used for a URL
+ * @return the VFS full path name
+ */
+ String getPathName(boolean url)
+ {
final StringBuilder builder = new StringBuilder(160);
final VirtualFile parent = this.parent;
if (parent == null) {
@@ -106,6 +118,18 @@
}
builder.append(name);
}
+
+ try
+ {
+ // Perhaps this should be cached to avoid the fs stat call?
+ if (url && isDirectory())
+ builder.append("/");
+ }
+ catch (IOException e)
+ {
+ // Don't care
+ }
+
return builder.toString();
}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java 2009-08-01 15:44:54 UTC (rev 91909)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/JavaZipFileSystem.java 2009-08-01 17:03:43 UTC (rev 91910)
@@ -55,6 +55,7 @@
public final class JavaZipFileSystem implements FileSystem
{
private final ZipFile zipFile;
+ private final File archiveFile;
private final long zipTime;
private final ZipNode rootNode;
private final TempDir tempDir;
@@ -84,9 +85,11 @@
zipTime = archiveFile.lastModified();
final ZipFile zipFile;
this.zipFile = zipFile = new ZipFile(archiveFile);
+ this.archiveFile = archiveFile;
this.tempDir = tempDir;
final Enumeration<? extends ZipEntry> entries = zipFile.entries();
final ZipNode rootNode = new ZipNode(new HashMap<String, ZipNode>(), "", null);
+
FILES: for (ZipEntry entry : iter(entries))
{
final String name = entry.getName();
@@ -159,6 +162,10 @@
if (cachedFile != null) {
return new FileInputStream(cachedFile);
}
+ if (rootNode == zipNode) {
+ return new FileInputStream(archiveFile);
+ }
+
final ZipEntry entry = zipNode.entry;
if (entry == null) {
throw new IOException("Not a file: \"" + target.getPathName() + "\"");
@@ -178,6 +185,11 @@
final ZipNode zipNode = getExistingZipNode(mountPoint, target);
final File cachedFile = zipNode.cachedFile;
final ZipEntry entry = zipNode.entry;
+
+ if (zipNode == rootNode) {
+ return archiveFile.length();
+ }
+
return cachedFile != null ? cachedFile.length() : entry == null ? 0L : entry.getSize();
}
More information about the jboss-cvs-commits
mailing list