[jboss-remoting-commits] JBoss Remoting SVN: r4147 - remoting2/branches/2.x/src/main/org/jboss/remoting/util.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu May 8 05:03:47 EDT 2008


Author: ron.sigal at jboss.com
Date: 2008-05-08 05:03:47 -0400 (Thu, 08 May 2008)
New Revision: 4147

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
Log:
JBREM-978: Added some file oriented methods.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-05-08 09:02:53 UTC (rev 4146)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/util/SecurityUtility.java	2008-05-08 09:03:47 UTC (rev 4147)
@@ -113,8 +113,59 @@
    // FilePermission methods
    ///////////////////////////////////////////////////////////////////////////////////////
    
+   static public File createTempFile(final String prefix, final String suffix, final boolean deleteOnExit) throws IOException
+   {
+      if (skipAccessControl)
+      {
+         File file =  File.createTempFile(prefix, suffix);
+         if (deleteOnExit) file.deleteOnExit();
+         return file;
+      }
+      
+      try
+      {
+         return (File)AccessController.doPrivileged( new PrivilegedExceptionAction()
+         {
+            public Object run() throws IOException
+            {
+               File file =  File.createTempFile(prefix, suffix);
+               if (deleteOnExit) file.deleteOnExit();
+               return file;
+            }
+         });
+      }
+      catch (PrivilegedActionException e)
+      {
+         throw (IOException) e.getCause();
+      }
+   }
+   
+   static public void deleteOnExit(final File file)
+   {
+      if (file == null)
+         return;
+      
+      if (skipAccessControl)
+      {
+         file.deleteOnExit();
+         return;
+      }
+
+      AccessController.doPrivileged( new PrivilegedAction()
+      {
+         public Object run()
+         {
+            file.deleteOnExit();
+            return null;
+         }
+      });
+   }
+   
    static public boolean fileExists(final File file)
    {
+      if (file == null)
+         return false;
+      
       if (skipAccessControl)
       {
          return file.exists();
@@ -170,7 +221,6 @@
       }
    }
    
-   
    static public FileInputStream getFileInputStream(final String path) throws FileNotFoundException
    {
       if (skipAccessControl)




More information about the jboss-remoting-commits mailing list