Author: sergiykarpenko
Date: 2010-11-19 09:37:41 -0500 (Fri, 19 Nov 2010)
New Revision: 3485
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
Log:
EXOJCR-986: PrivilegedFileHelper - few methods added
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
===================================================================
---
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-11-18
13:19:15 UTC (rev 3484)
+++
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-11-19
14:37:41 UTC (rev 3485)
@@ -232,6 +232,45 @@
}
/**
+ * Create new file.
+ *
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static boolean createNewFile(final File file) throws IOException
+ {
+ PrivilegedExceptionAction<Boolean> action = new
PrivilegedExceptionAction<Boolean>()
+ {
+ public Boolean run() throws Exception
+ {
+ return file.createNewFile();
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+
+ if (cause instanceof IOException)
+ {
+ throw (IOException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
* Create temporary file in privileged mode.
*
* @param prefix
@@ -424,6 +463,44 @@
}
/**
+ * Get file canonical path in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static String getCanonicalPath(final File file) throws IOException
+ {
+ PrivilegedExceptionAction<String> action = new
PrivilegedExceptionAction<String>()
+ {
+ public String run() throws Exception
+ {
+ return file.getCanonicalPath();
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof IOException)
+ {
+ throw (IOException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
* Delete file in privileged mode.
*
* @param file
Show replies by date