[jboss-cvs] JBossAS SVN: r98956 - projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 30 17:39:35 EST 2009
Author: johnbailey
Date: 2009-12-30 17:39:34 -0500 (Wed, 30 Dec 2009)
New Revision: 98956
Modified:
projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java
Log:
[JBAS-7342] - Updated VFSUtils to have another method for copying the contents of an InputStream to a VirtualFile
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-12-30 22:02:00 UTC (rev 98955)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/vfs/VFSUtils.java 2009-12-30 22:39:34 UTC (rev 98956)
@@ -344,6 +344,13 @@
return toURI(url).toURL();
}
+ /**
+ * Copy all the children from the original {@link VirtualFile} the target recursivly.
+ *
+ * @param original the file to copy children from
+ * @param target the file to copy the children to
+ * @throws IOException if any problems occur copying the files
+ */
public static void copyChildrenRecursive(VirtualFile original, VirtualFile target) throws IOException {
if(original == null) throw new IllegalArgumentException("Original VirtualFile must not be null");
if(target == null) throw new IllegalArgumentException("Target VirtualFile must not be null");
@@ -359,9 +366,7 @@
copyChildrenRecursive(child, targetChild);
} else {
FileInputStream is = new FileInputStream(childFile);
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- copyStreamAndClose(is, bos);
- writeFile(targetChild, bos.toByteArray());
+ writeFile(targetChild, is);
}
}
}
@@ -456,6 +461,22 @@
safeClose(fos);
}
}
+
+ /**
+ * Write the content from the given {@link InputStream} to the given virtual file, replacing its current contents (if any) or creating a new file if
+ * one does not exist.
+ *
+ * @param virtualFile the virtual file to write
+ * @param bytes the bytes
+ *
+ * @throws IOException if an error occurs
+ */
+ public static void writeFile(VirtualFile virtualFile, InputStream is) throws IOException {
+ final File file = virtualFile.getPhysicalFile();
+ file.getParentFile().mkdirs();
+ final FileOutputStream fos = new FileOutputStream(file);
+ copyStreamAndClose(is, fos);
+ }
/**
* Get the virtual URL for a virtual file. This URL can be used to access the virtual file; however, taking the file
More information about the jboss-cvs-commits
mailing list