[jboss-cvs] JBossAS SVN: r91770 - projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jul 29 11:18:59 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-07-29 11:18:59 -0400 (Wed, 29 Jul 2009)
New Revision: 91770

Modified:
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java
Log:
Add a convenience method to write a byte array into a file, similar to the old MemoryFileFactory API (except that it works with most FS types)

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-07-29 14:51:32 UTC (rev 91769)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFSUtils.java	2009-07-29 15:18:59 UTC (rev 91770)
@@ -26,6 +26,9 @@
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.io.Closeable;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.ByteArrayInputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -400,6 +403,26 @@
    }
 
    /**
+    * Write the given bytes 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, byte[] bytes) throws IOException
+   {
+      final File file = virtualFile.getPhysicalFile();
+      final FileOutputStream fos = new FileOutputStream(file);
+      try {
+         fos.write(bytes);
+         fos.close();
+      } finally {
+         safeClose(fos);
+      }
+   }
+
+   /**
     * Get the virtual URL for a virtual file.  This URL can be used to access the virtual file; however, taking the
     * file part of the URL and attempting to use it with the {@link java.io.File} class may fail if the file is not
     * present on the physical filesystem, and in general should not be attempted.




More information about the jboss-cvs-commits mailing list