Author: tolusha
Date: 2010-12-16 10:32:54 -0500 (Thu, 16 Dec 2010)
New Revision: 3671
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
Log:
EXOJCR-1090: allow to create zipInputStream in privileged mode
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-12-16
15:25:25 UTC (rev 3670)
+++
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-12-16
15:32:54 UTC (rev 3671)
@@ -30,6 +30,7 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
/**
@@ -235,6 +236,44 @@
/**
* Create FileInputStream in privileged mode.
*
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
+ public static ZipInputStream zipInputStream(final File file) throws
FileNotFoundException
+ {
+ PrivilegedExceptionAction<ZipInputStream> action = new
PrivilegedExceptionAction<ZipInputStream>()
+ {
+ public ZipInputStream run() throws Exception
+ {
+ return new ZipInputStream(new FileInputStream(file));
+ }
+ };
+ try
+ {
+ return AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof FileNotFoundException)
+ {
+ throw (FileNotFoundException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
+ /**
+ * Create FileInputStream in privileged mode.
+ *
* @param name
* @return
* @throws FileNotFoundException
Show replies by date