[exo-jcr-commits] exo-jcr SVN: r3669 - kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Dec 16 10:15:39 EST 2010
Author: tolusha
Date: 2010-12-16 10:15:39 -0500 (Thu, 16 Dec 2010)
New Revision: 3669
Modified:
kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java
Log:
EXOJCR-1090: allow to create zipOutputStream 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 12:45:04 UTC (rev 3668)
+++ kernel/trunk/exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/PrivilegedFileHelper.java 2010-12-16 15:15:39 UTC (rev 3669)
@@ -30,6 +30,7 @@
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
+import java.util.zip.ZipOutputStream;
/**
* @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
@@ -79,6 +80,44 @@
}
/**
+ * Create ZipOutputStream in privileged mode.
+ *
+ * @param file
+ * @return
+ * @throws FileNotFoundException
+ */
+ public static ZipOutputStream zipOutputStream(final File file) throws FileNotFoundException
+ {
+ PrivilegedExceptionAction<ZipOutputStream> action = new PrivilegedExceptionAction<ZipOutputStream>()
+ {
+ public ZipOutputStream run() throws Exception
+ {
+ return new ZipOutputStream(new FileOutputStream(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 FileOutputStream in privileged mode.
*
* @param name
More information about the exo-jcr-commits
mailing list