Author: tolusha
Date: 2010-06-14 02:34:22 -0400 (Mon, 14 Jun 2010)
New Revision: 2559
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
Log:
EXOJCR-756: BaseStandalone test uses Helper
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-11
15:05:59 UTC (rev 2558)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java 2010-06-14
06:34:22 UTC (rev 2559)
@@ -135,6 +135,42 @@
}
}
+ public static File createTempFile(final String prefix, final String suffix) throws
IllegalArgumentException,
+ IOException
+ {
+ PrivilegedExceptionAction<Object> action = new
PrivilegedExceptionAction<Object>()
+ {
+ public Object run() throws Exception
+ {
+ return File.createTempFile(prefix, suffix);
+ }
+ };
+ try
+ {
+ return (File)AccessController.doPrivileged(action);
+ }
+ catch (PrivilegedActionException pae)
+ {
+ Throwable cause = pae.getCause();
+ if (cause instanceof IllegalArgumentException)
+ {
+ throw (IllegalArgumentException)cause;
+ }
+ else if (cause instanceof IOException)
+ {
+ throw (IOException)cause;
+ }
+ else if (cause instanceof RuntimeException)
+ {
+ throw (RuntimeException)cause;
+ }
+ else
+ {
+ throw new RuntimeException(cause);
+ }
+ }
+ }
+
public static long length(final File file)
{
PrivilegedAction<Object> action = new PrivilegedAction<Object>()
@@ -147,6 +183,19 @@
return (Long)AccessController.doPrivileged(action);
}
+ public static void deleteOnExit(final File file)
+ {
+ PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+ {
+ public Object run()
+ {
+ file.deleteOnExit();
+ return null;
+ }
+ };
+ AccessController.doPrivileged(action);
+ }
+
public static String getAbsolutePath(final File file)
{
PrivilegedAction<Object> action = new PrivilegedAction<Object>()
Modified:
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2010-06-11
15:05:59 UTC (rev 2558)
+++
jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java 2010-06-14
06:34:22 UTC (rev 2559)
@@ -31,6 +31,7 @@
import org.exoplatform.services.jcr.impl.core.SessionImpl;
import org.exoplatform.services.jcr.impl.dataflow.serialization.ReaderSpoolFileHolder;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
import org.exoplatform.services.jcr.impl.util.io.WorkspaceFileCleanerHolder;
import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
import org.exoplatform.services.log.ExoLogger;
@@ -395,13 +396,7 @@
protected File createBLOBTempFile(int sizeInKb) throws IOException
{
- System.setSecurityManager(null);
-
- File file = createBLOBTempFile("exo_jcr_test_temp_file_", sizeInKb);
-
- System.setSecurityManager(new SecurityManager());
-
- return file;
+ return createBLOBTempFile("exo_jcr_test_temp_file_", sizeInKb);
}
protected File createBLOBTempFile(String prefix, int sizeInKb) throws IOException
@@ -409,8 +404,8 @@
// create test file
byte[] data = new byte[1024]; // 1Kb
- File testFile = File.createTempFile(prefix, ".tmp");
- FileOutputStream tempOut = new FileOutputStream(testFile);
+ File testFile = PrivilegedFileHelper.createTempFile(prefix, ".tmp");
+ FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
Random random = new Random();
for (int i = 0; i < sizeInKb; i++)
@@ -419,10 +414,11 @@
tempOut.write(data);
}
tempOut.close();
- testFile.deleteOnExit(); // delete on test exit
+ PrivilegedFileHelper.deleteOnExit(testFile); // delete on test exit
if (log.isDebugEnabled())
{
- log.debug("Temp file created: " + testFile.getAbsolutePath() + "
size: " + testFile.length());
+ log.debug("Temp file created: " +
PrivilegedFileHelper.getAbsolutePath(testFile) + " size: "
+ + PrivilegedFileHelper.length(testFile));
}
return testFile;
}