[jboss-cvs] JBossAS SVN: r91993 - in projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs: spi and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 4 21:51:08 EDT 2009
Author: david.lloyd at jboss.com
Date: 2009-08-04 21:51:08 -0400 (Tue, 04 Aug 2009)
New Revision: 91993
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java
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/spi/FileSystem.java
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JZipFileSystem.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:
Add recursive copy; also fix exceptions on methods that should not throw one
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java 2009-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -28,6 +28,7 @@
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FileInputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
@@ -547,7 +548,7 @@
*
* @return {@code true} if the file was deleted
*/
- public static boolean recursiveDelete(VirtualFile root) throws IOException {
+ public static boolean recursiveDelete(VirtualFile root) {
boolean ok = true;
if (root.isDirectory()) {
final List<VirtualFile> files = root.getChildren();
@@ -560,4 +561,112 @@
}
return ok;
}
+
+ /**
+ * Recursively copy a file or directory from one location to another.
+ *
+ * @param original the original file or directory
+ * @param destDir the destination directory
+ * @throws IOException if an I/O error occurs before the copy is complete
+ */
+ public static void recursiveCopy(File original, File destDir) throws IOException {
+ final String name = original.getName();
+ final File destFile = new File(destDir, name);
+ if (original.isDirectory()) {
+ destFile.mkdir();
+ for (File file : original.listFiles()) {
+ recursiveCopy(file, destFile);
+ }
+ } else {
+ final OutputStream os = new FileOutputStream(destFile);
+ try {
+ final InputStream is = new FileInputStream(original);
+ copyStreamAndClose(is, os);
+ } finally {
+ // in case the input stream open fails
+ safeClose(os);
+ }
+ }
+ }
+
+ /**
+ * Recursively copy a file or directory from one location to another.
+ *
+ * @param original the original file or directory
+ * @param destDir the destination directory
+ * @throws IOException if an I/O error occurs before the copy is complete
+ */
+ public static void recursiveCopy(File original, VirtualFile destDir) throws IOException {
+ final String name = original.getName();
+ final File destFile = destDir.getChild(name).getPhysicalFile();
+ if (original.isDirectory()) {
+ destFile.mkdir();
+ for (File file : original.listFiles()) {
+ recursiveCopy(file, destFile);
+ }
+ } else {
+ final OutputStream os = new FileOutputStream(destFile);
+ try {
+ final InputStream is = new FileInputStream(original);
+ copyStreamAndClose(is, os);
+ } finally {
+ // in case the input stream open fails
+ safeClose(os);
+ }
+ }
+ }
+
+ /**
+ * Recursively copy a file or directory from one location to another.
+ *
+ * @param original the original virtual file or directory
+ * @param destDir the destination directory
+ * @throws IOException if an I/O error occurs before the copy is complete
+ */
+ public static void recursiveCopy(VirtualFile original, File destDir) throws IOException {
+ final String name = original.getName();
+ final File destFile = new File(destDir, name);
+ if (original.isDirectory()) {
+ destFile.mkdir();
+ for (VirtualFile file : original.getChildren()) {
+ recursiveCopy(file, destFile);
+ }
+ } else {
+ final OutputStream os = new FileOutputStream(destFile);
+ try {
+ final InputStream is = original.openStream();
+ copyStreamAndClose(is, os);
+ } finally {
+ // in case the input stream open fails
+ safeClose(os);
+ }
+ }
+ }
+
+ /**
+ * Recursively copy a file or directory from one location to another.
+ *
+ * @param original the original virtual file or directory
+ * @param destDir the destination virtual directory
+ * @throws IOException if an I/O error occurs before the copy is complete
+ */
+ public static void recursiveCopy(VirtualFile original, VirtualFile destDir) throws IOException {
+ final String name = original.getName();
+ final File destFile = destDir.getChild(name).getPhysicalFile();
+ if (original.isDirectory()) {
+ destFile.mkdir();
+ for (VirtualFile file : original.getChildren()) {
+ recursiveCopy(file, destFile);
+ }
+ } else {
+ final OutputStream os = new FileOutputStream(destFile);
+ try {
+ final InputStream is = original.openStream();
+ copyStreamAndClose(is, os);
+ } finally {
+ // in case the input stream open fails
+ safeClose(os);
+ }
+ }
+ }
}
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-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VirtualFile.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -148,7 +148,7 @@
*
* @throws IOException - thrown on failure to detect existence.
*/
- public boolean exists() throws IOException {
+ public boolean exists() {
final VFS.Mount mount = VFS.instance.getMount(this);
return mount.getFileSystem().exists(mount.getMountPoint(), this);
}
@@ -197,7 +197,7 @@
*
* @throws IOException if an error occurs
*/
- public boolean delete() throws IOException {
+ public boolean delete() {
final VFS.Mount mount = VFS.instance.getMount(this);
return mount.getFileSystem().delete(mount.getMountPoint(), this);
}
@@ -274,7 +274,7 @@
*
* @throws IOException for any problem accessing the virtual file system
*/
- public List<VirtualFile> getChildren() throws IOException {
+ public List<VirtualFile> getChildren() {
if (!isDirectory())
return Collections.emptyList();
VFS vfs = VFS.instance;
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-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/FileSystem.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -81,10 +81,8 @@
* @param target the virtual file to act upon
*
* @return {@code true} if the file was deleted, {@code false} if it failed for any reason
- *
- * @throws IOException if an I/O error occurs
*/
- boolean delete(VirtualFile mountPoint, VirtualFile target) throws IOException;
+ boolean delete(VirtualFile mountPoint, VirtualFile target);
/**
* Get the size of a virtual file within this filesystem.
@@ -120,7 +118,7 @@
*
* @throws IOException if an I/O error occurs
*/
- boolean exists(VirtualFile mountPoint, VirtualFile target) throws IOException;
+ boolean exists(VirtualFile mountPoint, VirtualFile target);
/**
* Ascertain whether a virtual file within this filesystem is a directory.
@@ -129,8 +127,6 @@
* @param target the virtual file to act upon
*
* @return {@code true} if the file exists and is a directory, {@code false} otherwise
- *
- * @throws IOException if an I/O error occurs
*/
boolean isDirectory(VirtualFile mountPoint, VirtualFile target);
@@ -142,10 +138,8 @@
* @param target the virtual file to act upon
*
* @return the collection of children names
- *
- * @throws IOException if an I/O error occurs
*/
- List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) throws IOException;
+ List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target);
/**
* Destroy this filesystem instance. After this method is called, the filesystem may not be used in any way. This
Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JZipFileSystem.java 2009-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JZipFileSystem.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -154,8 +154,11 @@
return Zip.openEntry(zipFile, entry);
}
- public boolean delete(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public boolean delete(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return false;
+ }
final File cachedFile = zipNode.cachedFile;
return cachedFile != null && cachedFile.delete();
}
@@ -174,7 +177,7 @@
return cachedFile != null ? cachedFile.lastModified() : entry == null ? zipTime : entry.getModificationTime();
}
- public boolean exists(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public boolean exists(VirtualFile mountPoint, VirtualFile target) {
final ZipNode zipNode = rootNode.find(mountPoint, target);
if (zipNode == null) {
return false;
@@ -189,8 +192,11 @@
return zipNode != null && zipNode.entry == null;
}
- public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return Collections.emptyList();
+ }
final Map<String, ZipNode> children = zipNode.children;
if (children == null) {
return Collections.emptyList();
@@ -212,6 +218,14 @@
return entry;
}
+ private ZipNode getZipNode(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = rootNode.find(mountPoint, target);
+ if (zipNode == null) {
+ return null;
+ }
+ return zipNode;
+ }
+
private ZipNode getExistingZipNode(VirtualFile mountPoint, VirtualFile target)
throws FileNotFoundException {
final ZipNode zipNode = rootNode.find(mountPoint, target);
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-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -165,8 +165,11 @@
return zipFile.getInputStream(entry);
}
- public boolean delete(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public boolean delete(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return false;
+ }
final File cachedFile = zipNode.cachedFile;
return cachedFile != null && cachedFile.delete();
}
@@ -188,7 +191,7 @@
return cachedFile != null ? cachedFile.lastModified() : entry == null ? zipTime : entry.getTime();
}
- public boolean exists(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public boolean exists(VirtualFile mountPoint, VirtualFile target) {
final ZipNode zipNode = rootNode.find(mountPoint, target);
if (zipNode == null) {
return false;
@@ -203,8 +206,11 @@
return zipNode != null && zipNode.entry == null;
}
- public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) throws IOException {
- final ZipNode zipNode = getExistingZipNode(mountPoint, target);
+ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = getZipNode(mountPoint, target);
+ if (zipNode == null) {
+ return Collections.emptyList();
+ }
final Map<String, ZipNode> children = zipNode.children;
if (children == null) {
return Collections.emptyList();
@@ -226,6 +232,14 @@
return entry;
}
+ private ZipNode getZipNode(VirtualFile mountPoint, VirtualFile target) {
+ final ZipNode zipNode = rootNode.find(mountPoint, target);
+ if (zipNode == null) {
+ return null;
+ }
+ return zipNode;
+ }
+
private ZipNode getExistingZipNode(VirtualFile mountPoint, VirtualFile target)
throws FileNotFoundException {
final ZipNode zipNode = rootNode.find(mountPoint, target);
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-08-05 01:37:12 UTC (rev 91992)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/spi/RealFileSystem.java 2009-08-05 01:51:08 UTC (rev 91993)
@@ -81,7 +81,7 @@
/**
* {@inheritDoc}
*/
- public boolean delete(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public boolean delete(VirtualFile mountPoint, VirtualFile target) {
return getFile(mountPoint, target).delete();
}
@@ -102,7 +102,7 @@
/**
* {@inheritDoc}
*/
- public boolean exists(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public boolean exists(VirtualFile mountPoint, VirtualFile target) {
return getFile(mountPoint, target).exists();
}
@@ -116,7 +116,7 @@
/**
* {@inheritDoc}
*/
- public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) throws IOException {
+ public List<String> getDirectoryEntries(VirtualFile mountPoint, VirtualFile target) {
final String[] names = getFile(mountPoint, target).list();
return names == null ? Collections.<String>emptyList() : Arrays.asList(names);
}
More information about the jboss-cvs-commits
mailing list