[jboss-cvs] JBossAS SVN: r94623 - in projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs: protocol and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Oct 9 15:50:35 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-10-09 15:50:34 -0400 (Fri, 09 Oct 2009)
New Revision: 94623
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/FileSystem.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java
Log:
Change getLastModified and getSize to behave similarly to java.io.File, becuase that is the only behavior we can guarantee
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -124,7 +124,7 @@
*
* @throws IOException for any problem accessing the virtual file system
*/
- public long getLastModified() throws IOException {
+ public long getLastModified() {
final VFS.Mount mount = VFS.instance.getMount(this);
return mount.getFileSystem().getLastModified(mount.getMountPoint(), this);
}
@@ -136,7 +136,7 @@
*
* @throws IOException for any problem accessing the virtual file system
*/
- public long getSize() throws IOException {
+ public long getSize() {
final VFS.Mount mount = VFS.instance.getMount(this);
return mount.getFileSystem().getSize(mount.getMountPoint(), this);
}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/protocol/VirtualFileURLConnection.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -57,20 +57,12 @@
}
public int getContentLength() {
- try {
- final long size = file.getSize();
- return size > (long) Integer.MAX_VALUE ? -1 : (int) size;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ final long size = file.getSize();
+ return size > (long) Integer.MAX_VALUE ? -1 : (int) size;
}
public long getLastModified() {
- try {
- return file.getLastModified();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ return file.getLastModified();
}
public InputStream getInputStream() throws IOException {
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/AssemblyFileSystem.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -24,6 +24,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -33,185 +34,85 @@
/**
* FileSystem used to mount an Assembly into the VFS.
- *
+ *
* @author <a href="baileyje at gmail.com">John Bailey</a>
*/
public class AssemblyFileSystem implements FileSystem {
- private final VirtualFileAssembly assembly;
+ private final VirtualFileAssembly assembly;
- public AssemblyFileSystem(VirtualFileAssembly assembly) {
- this.assembly = assembly;
- }
+ public AssemblyFileSystem(VirtualFileAssembly assembly) {
+ this.assembly = assembly;
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#getFile(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public File getFile(VirtualFile mountPoint, VirtualFile target) throws IOException {
- return getVirtualFileAndRun(mountPoint, target, new VirtualFileTask<File>() {
- public File with(VirtualFile file) throws IOException {
- return file.getPhysicalFile();
- }
+ /** {@inheritDoc} */
+ public File getFile(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ if (assemblyFile == null) {
+ throw new FileNotFoundException(assemblyFile.getPathName());
+ }
+ return assemblyFile.getPhysicalFile();
+ }
- public File without() {
- return null;
- }
- });
- }
+ /** {@inheritDoc} */
+ public boolean delete(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ return assemblyFile != null && assemblyFile.delete();
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#delete(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public boolean delete(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
- if (assemblyFile == null) {
- return false;
- }
- return assemblyFile.delete();
- }
+ /** {@inheritDoc} */
+ public boolean exists(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ return assemblyFile != null && assemblyFile.exists();
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#exists(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public boolean exists(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
- if (assemblyFile == null) {
- return false;
- }
- return assemblyFile.exists();
- }
+ /** {@inheritDoc} */
+ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ if (assemblyFile == null) {
+ return Collections.<String>emptyList();
+ }
+ List<String> directoryEntries = new LinkedList<String>();
+ for (VirtualFile child : assemblyFile.getChildren()) {
+ directoryEntries.add(child.getName());
+ }
+ return directoryEntries;
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#getDirectoryEntries(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
- if (assemblyFile == null) {
- return Collections.<String> emptyList();
- }
- List<String> directoryEntries = new LinkedList<String>();
- for (VirtualFile child : assemblyFile.getChildren()) {
- directoryEntries.add(child.getName());
- }
- return directoryEntries;
- }
+ /** {@inheritDoc} */
+ public long getLastModified(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ return assemblyFile == null ? 0L : assemblyFile.getLastModified();
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#getLastModified(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public long getLastModified(VirtualFile mountPoint, VirtualFile target) throws IOException {
- return getVirtualFileAndRun(mountPoint, target, new VirtualFileTask<Long>() {
- public Long with(VirtualFile file) throws IOException {
- return file.getLastModified();
- }
+ /** {@inheritDoc} */
+ public long getSize(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ return assemblyFile == null ? 0L : assemblyFile.getSize();
+ }
- public Long without() {
- return -1L;
- }
- });
- }
+ /** {@inheritDoc} */
+ public boolean isDirectory(VirtualFile mountPoint, VirtualFile target) {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ return assemblyFile != null && assemblyFile.isDirectory();
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#getSize(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public long getSize(VirtualFile mountPoint, VirtualFile target) throws IOException {
- return getVirtualFileAndRun(mountPoint, target, new VirtualFileTask<Long>() {
- public Long with(VirtualFile file) throws IOException {
- return file.getSize();
- }
+ /** {@inheritDoc} */
+ public boolean isReadOnly() {
+ return false;
+ }
- public Long without() {
- return 0L;
- }
- });
- }
+ /** {@inheritDoc} */
+ public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
+ if (assemblyFile == null) {
+ throw new FileNotFoundException(assemblyFile.getPathName());
+ }
+ return assemblyFile.openStream();
+ }
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#isDirectory(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public boolean isDirectory(VirtualFile mountPoint, VirtualFile target) {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
- if (assemblyFile == null) {
- return false;
- }
- return assemblyFile.isDirectory();
- }
-
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#isReadOnly()
- */
- public boolean isReadOnly() {
- return false;
- }
-
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#openInputStream(org.jboss.vfs.VirtualFile, org.jboss.vfs.VirtualFile)
- */
- public InputStream openInputStream(VirtualFile mountPoint, VirtualFile target) throws IOException {
- return getVirtualFileAndRun(mountPoint, target, new VirtualFileTask<InputStream>() {
- public InputStream with(VirtualFile file) throws IOException {
- return file.openStream();
- }
-
- public InputStream without() {
- return null;
- }
- });
- }
-
- /*
- * {@inheritDoc}
- * @see org.jboss.vfs.spi.FileSystem#close()
- */
- public void close() throws IOException {
- assembly.close();
- }
-
- /**
- * Get the file for the mount/target combination and run the FileTask if the File is found otherwise return the
- * result of FileStask.getNullReturn.
- *
- * @param <T>
- * @param mountPoint
- * @param target
- * @param task
- * @return
- */
- private <T> T getVirtualFileAndRun(VirtualFile mountPoint, VirtualFile target, VirtualFileTask<T> task)
- throws IOException {
- VirtualFile assemblyFile = assembly.getFile(mountPoint, target);
- if (assemblyFile != null) {
- return task.with(assemblyFile);
- }
- return task.without();
- }
-
- /**
- * Task that can be run with a File.
- */
- private static interface VirtualFileTask<T> {
- /**
- * Method executed it the File is found.
- *
- * @param file
- * @return
- */
- T with(VirtualFile file) throws IOException;
-
- /**
- * Method executed if the File is not found.
- * @return
- */
- T without();
- }
-
+ /** {@inheritDoc} */
+ public void close() throws IOException {
+ assembly.close();
+ }
}
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/FileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/FileSystem.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/FileSystem.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -90,11 +90,9 @@
* @param mountPoint the mount point of the filesystem instance (guaranteed to be a parent of {@code target})
* @param target the virtual file to act upon
*
- * @return the size, in bytes
- *
- * @throws IOException if an I/O error occurs
+ * @return the size, in bytes, or 0L if the file does not exist or is a directory
*/
- long getSize(VirtualFile mountPoint, VirtualFile target) throws IOException;
+ long getSize(VirtualFile mountPoint, VirtualFile target);
/**
* Get the last modification time of a virtual file within this filesystem.
@@ -102,11 +100,9 @@
* @param mountPoint the mount point of the filesystem instance (guaranteed to be a parent of {@code target})
* @param target the virtual file to act upon
*
- * @return the modification time in milliseconds
- *
- * @throws IOException if an I/O error occurs
+ * @return the modification time in milliseconds, or 0L if the file does not exist or if an error occurs
*/
- long getLastModified(VirtualFile mountPoint, VirtualFile target) throws IOException;
+ long getLastModified(VirtualFile mountPoint, VirtualFile target);
/**
* Ascertain the existance of a virtual file within this filesystem.
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -175,8 +175,11 @@
return cachedFile != null && cachedFile.delete();
}
- public long getSize(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public long getSize(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return 0L;
+ }
final File cachedFile = zipNode.cachedFile;
final ZipEntry entry = zipNode.entry;
if (zipNode == rootNode) {
@@ -185,8 +188,11 @@
return cachedFile != null ? cachedFile.length() : entry == null ? 0L : entry.getSize();
}
- public long getLastModified(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public long getLastModified(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return 0L;
+ }
final File cachedFile = zipNode.cachedFile;
final ZipEntry entry = zipNode.entry;
return cachedFile != null ? cachedFile.lastModified() : entry == null ? zipTime : entry.getTime();
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java 2009-10-09 19:49:53 UTC (rev 94622)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java 2009-10-09 19:50:34 UTC (rev 94623)
@@ -88,14 +88,14 @@
/**
* {@inheritDoc}
*/
- public long getSize(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public long getSize(VirtualFile mountPoint, VirtualFile target) {
return getFile(mountPoint, target).length();
}
/**
* {@inheritDoc}
*/
- public long getLastModified(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public long getLastModified(VirtualFile mountPoint, VirtualFile target) {
return getFile(mountPoint, target).lastModified();
}
More information about the jboss-cvs-commits
mailing list