[exo-jcr-commits] exo-jcr SVN: r2563 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/config and 31 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Jun 14 03:38:12 EDT 2010


Author: tolusha
Date: 2010-06-14 03:38:11 -0400 (Mon, 14 Jun 2010)
New Revision: 2563

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/TextExtractorJob.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
   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/xml/BufferedDecoder.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportImport.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/AbstractImportTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRestoreWorkspaceInitializer.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestFileBasedNamespaceMappings.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCleanableFileStreamValueData.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationLogTestLoad.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationVSJavaSerializationTestLoad.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/MultipleDeserializationTestLoad.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestEOFException.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/ValueStoragePluginTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileValueIO.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/TestValueFileIOHelper.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/tools/tree/generator/RandomValueNodeGenerator.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueDataSpooling.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/java/TestFileLock.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestExportBigFiles.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestLoadRepo.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestPerformance.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/fs/TestFSReadWrite.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/RemoveVDTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/TestExportImportAmongSessions.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/export/ExportWorkspaceSystemViewTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/version/FileRestoreTest.java
Log:
EXOJCR-756: replace new FileOutputStream on PrivilegedFileHelper.fileOutputStream()

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/RepositoryContainer.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -64,9 +64,6 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
 import java.util.List;
 
 import javax.jcr.NamespaceRegistry;
@@ -621,5 +618,5 @@
       ntManager.start();
 
    }
-   
+
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/WorkspaceContainer.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -56,7 +56,6 @@
    public WorkspaceContainer(RepositoryContainer parent, WorkspaceEntry config) throws RepositoryException,
       RepositoryConfigurationException
    {
-
       // Before repository instantiation
       super(new MX4JComponentAdapterFactory(), parent);
 

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/config/RepositoryServiceConfigurationImpl.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -24,6 +24,7 @@
 import org.exoplatform.services.jcr.config.ConfigurationPersister;
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
 import org.exoplatform.services.jcr.config.RepositoryServiceConfiguration;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.naming.InitialContextInitializer;
 import org.jibx.runtime.BindingDirectory;
 import org.jibx.runtime.IBindingFactory;
@@ -35,7 +36,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -122,13 +122,14 @@
     * (non-Javadoc)
     * @see org.exoplatform.services.jcr.config.RepositoryServiceConfiguration#isRetainable()
     */
+   @Override
    public boolean isRetainable()
    {
       if (configurationPersister != null)
       {
          return true;
       }
-      
+
       String strfileUri = param.getValue();
       URL fileURL;
       try
@@ -148,6 +149,7 @@
     * 
     * @throws RepositoryException
     */
+   @Override
    public synchronized void retain() throws RepositoryException
    {
       try
@@ -173,7 +175,7 @@
             File backUp = new File(sourceConfig.getAbsoluteFile() + "_" + format.format(new Date()));
             if (!sourceConfig.renameTo(backUp))
                throw new RepositoryException("Can't back up configuration on path " + sourceConfig.getAbsolutePath());
-            saveStream = new FileOutputStream(sourceConfig);
+            saveStream = PrivilegedFileHelper.fileOutputStream(sourceConfig);
          }
 
          IBindingFactory bfact = BindingDirectory.getFactory(RepositoryServiceConfiguration.class);
@@ -258,7 +260,7 @@
             // Will be merged extension repository configuration with configuration from persister.  
             if (!configExtensionPaths.isEmpty())
             {
-               String[] paths = (String[]) configExtensionPaths.toArray(new String[configExtensionPaths.size()]);
+               String[] paths = configExtensionPaths.toArray(new String[configExtensionPaths.size()]);
                for (int i = paths.length - 1; i >= 0; i--)
                {
                   merge(configurationService.getInputStream(paths[i]));
@@ -273,7 +275,7 @@
          else
          {
 
-            String[] paths = (String[]) configExtensionPaths.toArray(new String[configExtensionPaths.size()]);
+            String[] paths = configExtensionPaths.toArray(new String[configExtensionPaths.size()]);
             for (int i = paths.length - 1; i >= 0; i--)
             {
                // We start from the last one because as it is the one with highest priorityn

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/BackupWorkspaceInitializer.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -31,17 +31,15 @@
 import org.exoplatform.services.jcr.datamodel.IllegalNameException;
 import org.exoplatform.services.jcr.datamodel.ItemData;
 import org.exoplatform.services.jcr.datamodel.NodeData;
-import org.exoplatform.services.jcr.datamodel.ValueData;
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
 import org.exoplatform.services.jcr.impl.core.value.ValueFactoryImpl;
-import org.exoplatform.services.jcr.impl.dataflow.TransientPropertyData;
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
 import org.exoplatform.services.jcr.impl.storage.JCRInvalidItemStateException;
 import org.exoplatform.services.jcr.impl.storage.JCRItemExistsException;
 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.SpoolFile;
 import org.exoplatform.services.jcr.observation.ExtendedEvent;
 
@@ -77,7 +75,7 @@
    private final String restoreDir;
 
    private FileCleaner fileCleaner;
-   
+
    /**
     * Temporary directory;
     */
@@ -101,10 +99,11 @@
          throw new RepositoryException("Can't find full backup file");
       else
          restorePath = fullBackupPath;
-      
+
       this.tempDir = new File(System.getProperty("java.io.tmpdir"));
    }
 
+   @Override
    public NodeData initWorkspace() throws RepositoryException
    {
 
@@ -383,7 +382,7 @@
       byte[] buf = new byte[bufferSize];
 
       File tempFile = SpoolFile.createTempFile("vdincb" + System.currentTimeMillis(), ".stmp", tempDir);
-      FileOutputStream fos = new FileOutputStream(tempFile);
+      FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
       long readBytes = fileSize;
 
       while (readBytes > 0)

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/SysViewWorkspaceInitializer.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -43,6 +43,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.persistent.CacheableWorkspaceDataManager;
 import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
 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.SpoolFile;
 import org.exoplatform.services.jcr.storage.WorkspaceDataContainer;
 import org.exoplatform.services.log.ExoLogger;
@@ -118,6 +119,7 @@
          return buf.length;
       }
 
+      @Override
       public void close()
       {
          buf = null;
@@ -182,6 +184,7 @@
          this.string.append(text);
       }
 
+      @Override
       boolean isText()
       {
          return true;
@@ -255,7 +258,9 @@
          {
             if (buffer.length >= maxBufferSize)
             {
-               buff = new FileOutputStream(tmpFile = SpoolFile.createTempFile("jcrrestorewi", ".tmp", tempDir));
+               buff =
+                  PrivilegedFileHelper.fileOutputStream(tmpFile =
+                     SpoolFile.createTempFile("jcrrestorewi", ".tmp", tempDir));
             }
             else
             {
@@ -265,7 +270,9 @@
          else if (tmpFile == null && (((TempOutputStream)buff).getSize() + buffer.length) > maxBufferSize)
          {
             // spool to file
-            FileOutputStream fout = new FileOutputStream(tmpFile = SpoolFile.createTempFile("jcrrestorewi", ".tmp", tempDir));
+            FileOutputStream fout =
+               PrivilegedFileHelper.fileOutputStream(tmpFile =
+                  SpoolFile.createTempFile("jcrrestorewi", ".tmp", tempDir));
             fout.write(((TempOutputStream)buff).getBuffer());
             buff.close();
             buff = fout; // use file
@@ -409,7 +416,7 @@
          throw new RepositoryConfigurationException("Workspace (" + workspaceName
             + ") RestoreIntializer should have mandatory parameter "
             + SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER);
-      
+
       this.tempDir = new File(System.getProperty("java.io.tmpdir"));
    }
 
@@ -455,7 +462,7 @@
          config.getContainer().getParameterInteger(WorkspaceDataContainer.MAXBUFFERSIZE_PROP,
             WorkspaceDataContainer.DEF_MAXBUFFERSIZE);
       this.restorePath = restorePath;
-      
+
       this.tempDir = new File(System.getProperty("java.io.tmpdir"));
    }
 
@@ -771,7 +778,7 @@
                            }
                            else
                            {
-                              
+
                               File pfile = propertyValue.getFile();
                               if (pfile != null)
                               {

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/ErrorLog.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -17,6 +17,7 @@
 
 package org.exoplatform.services.jcr.impl.core.query;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
@@ -103,7 +104,7 @@
          log.getParentFile().mkdirs();
          log.createNewFile();
 
-         out = new FileOutputStream(log).getChannel();
+         out = PrivilegedFileHelper.fileOutputStream(log).getChannel();
          out.position(1024 * fileSize - 1);
          out.write(ByteBuffer.wrap(new byte[]{0}));
          out.position(0);
@@ -111,7 +112,7 @@
       }
       else
       {
-         out = new FileOutputStream(log, true).getChannel();
+         out = PrivilegedFileHelper.fileOutputStream(log, true).getChannel();
       }
    }
 
@@ -155,7 +156,7 @@
       {
          out.truncate(0);
          out.close();
-         out = new FileOutputStream(logFile).getChannel();
+         out = PrivilegedFileHelper.fileOutputStream(logFile).getChannel();
          out.position(1024 * fileSize - 1);
          out.write(ByteBuffer.wrap(new byte[]{0}));
          out.position(0);
@@ -173,7 +174,7 @@
    {
       if (out == null)
       {
-         FileOutputStream os = new FileOutputStream(logFile, false);
+         FileOutputStream os = PrivilegedFileHelper.fileOutputStream(logFile, false);
          out = os.getChannel();
       }
    }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/FileBasedNamespaceMappings.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -16,10 +16,13 @@
  */
 package org.exoplatform.services.jcr.impl.core.query.lucene;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -31,9 +34,6 @@
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  * The class <code>NamespaceMappings</code> implements a
  * {@link NamespaceResolver} that holds a namespace
@@ -44,148 +44,169 @@
  * prefix is created on the fly and associated with the namespace. Known
  * namespace mappings are stored in a properties file.
  */
-public class FileBasedNamespaceMappings extends AbstractNamespaceMappings {
+public class FileBasedNamespaceMappings extends AbstractNamespaceMappings
+{
 
-    /**
-     * Default logger instance for this class
-     */
-    private static Logger log = LoggerFactory.getLogger("exo.jcr.component.core.NamespaceMappings");
+   /**
+    * Default logger instance for this class
+    */
+   private static Logger log = LoggerFactory.getLogger("exo.jcr.component.core.NamespaceMappings");
 
-    /**
-     * Location of the file that persists the uri / prefix mappings
-     */
-    private final File storage;
+   /**
+    * Location of the file that persists the uri / prefix mappings
+    */
+   private final File storage;
 
-    /**
-     * Map of uris indexed by prefixes
-     */
-    private Map prefixToURI = new HashMap();
+   /**
+    * Map of uris indexed by prefixes
+    */
+   private Map prefixToURI = new HashMap();
 
-    /**
-     * Map of prefixes indexed by uris
-     */
-    private Map uriToPrefix = new HashMap();
+   /**
+    * Map of prefixes indexed by uris
+    */
+   private Map uriToPrefix = new HashMap();
 
-    /**
-     * Current prefix count.
-     */
-    private int prefixCount;
+   /**
+    * Current prefix count.
+    */
+   private int prefixCount;
 
-    /**
-     * Creates <code>NamespaceMappings</code> instance. Initial mappings are
-     * loaded from <code>file</code>.
-     *
-     * @param file the <code>File</code> to load initial mappings.
-     * @throws IOException if an error occurs while reading initial namespace
-     *                     mappings from <code>file</code>.
-     */
-    public FileBasedNamespaceMappings(File file) throws IOException {
-        storage = file;
-        load();
-    }
+   /**
+    * Creates <code>NamespaceMappings</code> instance. Initial mappings are
+    * loaded from <code>file</code>.
+    *
+    * @param file the <code>File</code> to load initial mappings.
+    * @throws IOException if an error occurs while reading initial namespace
+    *                     mappings from <code>file</code>.
+    */
+   public FileBasedNamespaceMappings(File file) throws IOException
+   {
+      storage = file;
+      load();
+   }
 
-    /**
-     * Returns a namespace uri for a <code>prefix</code>.
-     *
-     * @param prefix the namespace prefix.
-     * @return the namespace uri.
-     * @throws NamespaceException if no namespace uri is registered for
-     *                            <code>prefix</code>.
-     */
-    public synchronized String getNamespaceURIByPrefix(String prefix) throws NamespaceException {
-        if (!prefixToURI.containsKey(prefix)) {
-            throw new NamespaceException(prefix + ": is not a registered namespace prefix.");
-        }
-        return (String) prefixToURI.get(prefix);
-    }
+   /**
+    * Returns a namespace uri for a <code>prefix</code>.
+    *
+    * @param prefix the namespace prefix.
+    * @return the namespace uri.
+    * @throws NamespaceException if no namespace uri is registered for
+    *                            <code>prefix</code>.
+    */
+   public synchronized String getNamespaceURIByPrefix(String prefix) throws NamespaceException
+   {
+      if (!prefixToURI.containsKey(prefix))
+      {
+         throw new NamespaceException(prefix + ": is not a registered namespace prefix.");
+      }
+      return (String)prefixToURI.get(prefix);
+   }
 
-    /**
-     * Returns a prefix for the namespace <code>uri</code>. If a namespace
-     * mapping exists, the already known prefix is returned; otherwise a new
-     * prefix is created and assigned to the namespace uri.
-     *
-     * @param uri the namespace uri.
-     * @return the prefix for the namespace uri.
-     * @throws NamespaceException if an yet unknown namespace uri / prefix
-     *                            mapping could not be stored.
-     */
-    public synchronized String getNamespacePrefixByURI(String uri) throws NamespaceException {
-        String prefix = (String) uriToPrefix.get(uri);
-        if (prefix == null) {
-            // make sure prefix is not taken
-            while (prefixToURI.get(String.valueOf(prefixCount)) != null) {
-                prefixCount++;
-            }
-            prefix = String.valueOf(prefixCount);
-            prefixToURI.put(prefix, uri);
-            uriToPrefix.put(uri, prefix);
-            log.debug("adding new namespace mapping: " + prefix + " -> " + uri);
-            try {
-                store();
-            } catch (IOException e) {
-                throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e);
-            }
-        }
-        return prefix;
-    }
+   /**
+    * Returns a prefix for the namespace <code>uri</code>. If a namespace
+    * mapping exists, the already known prefix is returned; otherwise a new
+    * prefix is created and assigned to the namespace uri.
+    *
+    * @param uri the namespace uri.
+    * @return the prefix for the namespace uri.
+    * @throws NamespaceException if an yet unknown namespace uri / prefix
+    *                            mapping could not be stored.
+    */
+   public synchronized String getNamespacePrefixByURI(String uri) throws NamespaceException
+   {
+      String prefix = (String)uriToPrefix.get(uri);
+      if (prefix == null)
+      {
+         // make sure prefix is not taken
+         while (prefixToURI.get(String.valueOf(prefixCount)) != null)
+         {
+            prefixCount++;
+         }
+         prefix = String.valueOf(prefixCount);
+         prefixToURI.put(prefix, uri);
+         uriToPrefix.put(uri, prefix);
+         log.debug("adding new namespace mapping: " + prefix + " -> " + uri);
+         try
+         {
+            store();
+         }
+         catch (IOException e)
+         {
+            throw new NamespaceException("Could not obtain a prefix for uri: " + uri, e);
+         }
+      }
+      return prefix;
+   }
 
-    //-----------------------< internal >---------------------------------------
+   //-----------------------< internal >---------------------------------------
 
-    /**
-     * Loads currently known mappings from a .properties file.
-     *
-     * @throws IOException if an error occurs while reading from the file.
-     */
-    private void load() throws IOException {
-        if (storage.exists()) {
-            InputStream in = new FileInputStream(storage);
-            try {
-                Properties props = new Properties();
-                log.debug("loading namespace mappings...");
-                props.load(in);
+   /**
+    * Loads currently known mappings from a .properties file.
+    *
+    * @throws IOException if an error occurs while reading from the file.
+    */
+   private void load() throws IOException
+   {
+      if (storage.exists())
+      {
+         InputStream in = new FileInputStream(storage);
+         try
+         {
+            Properties props = new Properties();
+            log.debug("loading namespace mappings...");
+            props.load(in);
 
-                // read mappings from properties
-                Iterator iter = props.keySet().iterator();
-                while (iter.hasNext()) {
-                    String prefix = (String) iter.next();
-                    String uri = props.getProperty(prefix);
-                    log.debug(prefix + " -> " + uri);
-                    prefixToURI.put(prefix, uri);
-                    uriToPrefix.put(uri, prefix);
-                }
-                prefixCount = props.size();
-                log.debug("namespace mappings loaded.");
-            } finally {
-                in.close();
+            // read mappings from properties
+            Iterator iter = props.keySet().iterator();
+            while (iter.hasNext())
+            {
+               String prefix = (String)iter.next();
+               String uri = props.getProperty(prefix);
+               log.debug(prefix + " -> " + uri);
+               prefixToURI.put(prefix, uri);
+               uriToPrefix.put(uri, prefix);
             }
-        }
-    }
+            prefixCount = props.size();
+            log.debug("namespace mappings loaded.");
+         }
+         finally
+         {
+            in.close();
+         }
+      }
+   }
 
-    /**
-     * Writes the currently known mappings into a .properties file.
-     *
-     * @throws IOException if an error occurs while writing the file.
-     */
-    private void store() throws IOException {
-        Properties props = new Properties();
+   /**
+    * Writes the currently known mappings into a .properties file.
+    *
+    * @throws IOException if an error occurs while writing the file.
+    */
+   private void store() throws IOException
+   {
+      Properties props = new Properties();
 
-        // store mappings in properties
-        Iterator iter = prefixToURI.keySet().iterator();
-        while (iter.hasNext()) {
-            String prefix = (String) iter.next();
-            String uri = (String) prefixToURI.get(prefix);
-            props.setProperty(prefix, uri);
-        }
+      // store mappings in properties
+      Iterator iter = prefixToURI.keySet().iterator();
+      while (iter.hasNext())
+      {
+         String prefix = (String)iter.next();
+         String uri = (String)prefixToURI.get(prefix);
+         props.setProperty(prefix, uri);
+      }
 
-        OutputStream out = new FileOutputStream(storage);
-        try {
-            out = new BufferedOutputStream(out);
-            props.store(out, null);
-        } finally {
-            // make sure stream is closed
-            out.close();
-        }
-    }
+      OutputStream out = PrivilegedFileHelper.fileOutputStream(storage);
+      try
+      {
+         out = new BufferedOutputStream(out);
+         props.store(out, null);
+      }
+      finally
+      {
+         // make sure stream is closed
+         out.close();
+      }
+   }
 
    public String[] getAllNamespacePrefixes() throws RepositoryException
    {

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/TextExtractorJob.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/TextExtractorJob.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/query/lucene/TextExtractorJob.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,12 +20,12 @@
 import EDU.oswego.cs.dl.util.concurrent.FutureResult;
 
 import org.exoplatform.services.document.DocumentReader;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -173,6 +173,7 @@
    /**
     * @return a String description for this job with the mime type.
     */
+   @Override
    public String toString()
    {
       return "TextExtractorJob for " + type;
@@ -213,7 +214,7 @@
       Writer out;
       try
       {
-         out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(temp), ENCODING_UTF8));
+         out = new BufferedWriter(new OutputStreamWriter(PrivilegedFileHelper.fileOutputStream(temp), ENCODING_UTF8));
       }
       catch (IOException e)
       {
@@ -242,6 +243,7 @@
 
          return new InputStreamReader(in, ENCODING_UTF8)
          {
+            @Override
             public void close() throws IOException
             {
                super.close();

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.jcr.impl.dataflow;
 
 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.SpoolFile;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -26,7 +27,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -125,7 +125,7 @@
          this.maxIOBuffSize = calcMaxIOSize();
 
          SpoolFile sf = SpoolFile.createTempFile("jcrvdedit", null, tempDirectory);
-         OutputStream sfout = new FileOutputStream(sf);
+         OutputStream sfout = PrivilegedFileHelper.fileOutputStream(sf);
          try
          {
             byte[] tmpBuff = new byte[2048];

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -480,7 +480,7 @@
          {
             SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
             sf.acquire(this);
-            sfout = new FileOutputStream(sf);
+            sfout = PrivilegedFileHelper.fileOutputStream(sf);
 
             while ((read = tmpStream.read(tmpBuff)) >= 0)
                sfout.write(tmpBuff, 0, read);

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/serialization/PersistedValueDataReader.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -23,9 +23,9 @@
 import org.exoplatform.services.jcr.dataflow.serialization.UnknownClassIdException;
 import org.exoplatform.services.jcr.impl.dataflow.AbstractPersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
-import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
 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.SpoolFile;
 
 import java.io.File;
@@ -145,7 +145,7 @@
    private void writeToFile(ObjectReader src, SpoolFile dest, long length) throws IOException
    {
       // write data to file
-      FileOutputStream sfout = new FileOutputStream(dest);
+      FileOutputStream sfout = PrivilegedFileHelper.fileOutputStream(dest);
       int bSize = SerializationConstants.INTERNAL_BUFFER_SIZE;
       try
       {

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCStorageConnection.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -40,6 +40,7 @@
 import org.exoplatform.services.jcr.impl.storage.value.ValueStorageNotFoundException;
 import org.exoplatform.services.jcr.impl.storage.value.fs.operations.ValueFileIOHelper;
 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.SwapFile;
 import org.exoplatform.services.jcr.storage.WorkspaceStorageConnection;
 import org.exoplatform.services.jcr.storage.value.ValueIOChannel;
@@ -49,7 +50,6 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -82,6 +82,7 @@
       /**
        * {@inheritDoc}
        */
+      @Override
       public void writeStreamedValue(File file, ValueData value) throws IOException
       {
          super.writeStreamedValue(file, value);
@@ -716,7 +717,7 @@
          if (LOG.isDebugEnabled())
          {
             LOG.debug("Node deleted " + data.getQPath().getAsString() + ", " + data.getIdentifier() + ", "
-               + ((NodeData)data).getPrimaryTypeName().getAsString());
+               + (data).getPrimaryTypeName().getAsString());
          }
 
       }
@@ -758,12 +759,8 @@
 
          if (LOG.isDebugEnabled())
          {
-            LOG.debug("Property deleted "
-               + data.getQPath().getAsString()
-               + ", "
-               + data.getIdentifier()
-               + (((PropertyData)data).getValues() != null ? ", values count: "
-                  + ((PropertyData)data).getValues().size() : ", NULL data"));
+            LOG.debug("Property deleted " + data.getQPath().getAsString() + ", " + data.getIdentifier()
+               + ((data).getValues() != null ? ", values count: " + (data).getValues().size() : ", NULL data"));
          }
 
       }
@@ -2313,7 +2310,7 @@
                      buffer = null;
                      break;
                   }
-                  out = new FileOutputStream(swapFile);
+                  out = PrivilegedFileHelper.fileOutputStream(swapFile);
                   out.write(buffer, 0, len);
                   out.write(spoolBuffer, 0, read);
                   buffer = null;

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/cas/JDBCValueContentAddressStorageImpl.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -24,6 +24,9 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
 import java.sql.PreparedStatement;
@@ -98,17 +101,16 @@
     */
    private static final String DB2_PK_CONSTRAINT_DETECT_PATTERN =
       "(.*DB2 SQL error+.*SQLCODE: -803+.*SQLSTATE: 23505+.*%s.*)+?";
-   
+
    /**
     * MYSQL_PK_CONSTRAINT_DETECT_PATTERN.
     */
-   private static final String H2_PK_CONSTRAINT_DETECT_PATTERN = 
-      "(.*JdbcSQLException.*violation.*PRIMARY_KEY_.*)";
-   
+   private static final String H2_PK_CONSTRAINT_DETECT_PATTERN = "(.*JdbcSQLException.*violation.*PRIMARY_KEY_.*)";
+
    /**
     * H2_PK_CONSTRAINT_DETECT.
     */
-   private static final Pattern H2_PK_CONSTRAINT_DETECT = 
+   private static final Pattern H2_PK_CONSTRAINT_DETECT =
       Pattern.compile(H2_PK_CONSTRAINT_DETECT_PATTERN, Pattern.CASE_INSENSITIVE);
 
    /**
@@ -158,7 +160,34 @@
          Statement st = null;
          try
          {
-            conn = dataSource.getConnection();
+            PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+            {
+               public Object run() throws Exception
+               {
+                  return dataSource.getConnection();
+               }
+            };
+            try
+            {
+               conn = (Connection)AccessController.doPrivileged(action);
+            }
+            catch (PrivilegedActionException pae)
+            {
+               Throwable cause = pae.getCause();
+               if (cause instanceof SQLException)
+               {
+                  throw (SQLException)cause;
+               }
+               else if (cause instanceof RuntimeException)
+               {
+                  throw (RuntimeException)cause;
+               }
+               else
+               {
+                  throw new RuntimeException(cause);
+               }
+            }
+
             DatabaseMetaData dbMetaData = conn.getMetaData();
 
             String dialect = props.getProperty(JDBC_DIALECT_PARAM);
@@ -352,7 +381,7 @@
       {
          return DB2_PK_CONSTRAINT_DETECT.matcher(err).find();
       }
-      else if (DBConstants.DB_DIALECT_H2.equalsIgnoreCase(dialect)) 
+      else if (DBConstants.DB_DIALECT_H2.equalsIgnoreCase(dialect))
       {
          return H2_PK_CONSTRAINT_DETECT.matcher(err).find();
       }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
@@ -171,7 +172,7 @@
       {
          public Object run() throws Exception
          {
-            OutputStream out = new FileOutputStream(file);
+            OutputStream out = PrivilegedFileHelper.fileOutputStream(file);
             try
             {
                out.write(value.getAsByteArray());
@@ -231,7 +232,7 @@
                if (streamed.isPersisted())
                {
                   // already persisted in another Value, copy it to this Value
-                  copyClose(streamed.getAsStream(), new FileOutputStream(file));
+                  copyClose(streamed.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
                }
                else
                {
@@ -250,13 +251,13 @@
                                  + tempFile.getAbsolutePath() + ". Destination: " + file.getAbsolutePath());
                         }
 
-                        copyClose(new FileInputStream(tempFile), new FileOutputStream(file));
+                        copyClose(new FileInputStream(tempFile), PrivilegedFileHelper.fileOutputStream(file));
                      }
                   }
                   else
                   {
                      // not spooled, use client InputStream
-                     copyClose(streamed.getStream(), new FileOutputStream(file));
+                     copyClose(streamed.getStream(), PrivilegedFileHelper.fileOutputStream(file));
                   }
 
                   // link this Value to file in VS
@@ -266,7 +267,7 @@
             else
             {
                // copy from Value stream to the file, e.g. from FilePersistedValueData to this Value
-               copyClose(value.getAsStream(), new FileOutputStream(file));
+               copyClose(value.getAsStream(), PrivilegedFileHelper.fileOutputStream(file));
             }
 
             return null;

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileOperation.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -132,7 +132,7 @@
                // lock file in temp directory
                lockFile = new File(tempDir, targetFile.getName() + LOCK_FILE_EXTENSION);
 
-               FileOutputStream lout = new FileOutputStream(lockFile, true);
+               FileOutputStream lout = PrivilegedFileHelper.fileOutputStream(lockFile, true);
                lout.write(operationInfo.getBytes()); // TODO write info
                lout.getChannel().lock(); // wait for unlock (on Windows will wait for this JVM too)
 

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/SecurityHelper.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -92,4 +92,5 @@
          }
       }
    }
+
 }

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-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/util/io/PrivilegedFileHelper.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -39,16 +39,16 @@
 
    public static FileOutputStream fileOutputStream(final File file) throws FileNotFoundException
    {
-      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
       {
-         public Object run() throws Exception
+         public FileOutputStream run() throws Exception
          {
             return new FileOutputStream(file);
          }
       };
       try
       {
-         return (FileOutputStream)AccessController.doPrivileged(action);
+         return AccessController.doPrivileged(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -68,18 +68,80 @@
       }
    }
 
+   public static FileOutputStream fileOutputStream(final String name) throws FileNotFoundException
+   {
+      PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
+      {
+         public FileOutputStream run() throws Exception
+         {
+            return new FileOutputStream(name);
+         }
+      };
+      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);
+         }
+      }
+   }
+
+   public static FileOutputStream fileOutputStream(final File file, final boolean append) throws FileNotFoundException
+   {
+      PrivilegedExceptionAction<FileOutputStream> action = new PrivilegedExceptionAction<FileOutputStream>()
+      {
+         public FileOutputStream run() throws Exception
+         {
+            return new FileOutputStream(file, append);
+         }
+      };
+      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);
+         }
+      }
+   }
+
    public static FileInputStream fileInputStream(final File file) throws FileNotFoundException
    {
-      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      PrivilegedExceptionAction<FileInputStream> action = new PrivilegedExceptionAction<FileInputStream>()
       {
-         public Object run() throws Exception
+         public FileInputStream run() throws Exception
          {
             return new FileInputStream(file);
          }
       };
       try
       {
-         return (FileInputStream)AccessController.doPrivileged(action);
+         return AccessController.doPrivileged(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -102,16 +164,16 @@
    public static File createTempFile(final String prefix, final String suffix, final File directory)
       throws IllegalArgumentException, IOException
    {
-      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      PrivilegedExceptionAction<File> action = new PrivilegedExceptionAction<File>()
       {
-         public Object run() throws Exception
+         public File run() throws Exception
          {
             return File.createTempFile(prefix, suffix, directory);
          }
       };
       try
       {
-         return (File)AccessController.doPrivileged(action);
+         return AccessController.doPrivileged(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -138,16 +200,16 @@
    public static File createTempFile(final String prefix, final String suffix) throws IllegalArgumentException,
       IOException
    {
-      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      PrivilegedExceptionAction<File> action = new PrivilegedExceptionAction<File>()
       {
-         public Object run() throws Exception
+         public File run() throws Exception
          {
             return File.createTempFile(prefix, suffix);
          }
       };
       try
       {
-         return (File)AccessController.doPrivileged(action);
+         return AccessController.doPrivileged(action);
       }
       catch (PrivilegedActionException pae)
       {
@@ -173,14 +235,14 @@
 
    public static long length(final File file)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<Long> action = new PrivilegedAction<Long>()
       {
-         public Object run()
+         public Long run()
          {
             return new Long(file.length());
          }
       };
-      return (Long)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static void deleteOnExit(final File file)
@@ -198,38 +260,38 @@
 
    public static String getAbsolutePath(final File file)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<String> action = new PrivilegedAction<String>()
       {
-         public Object run()
+         public String run()
          {
             return file.getAbsolutePath();
          }
       };
-      return (String)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static boolean delete(final File file)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
       {
-         public Object run()
+         public Boolean run()
          {
             return file.delete();
          }
       };
-      return (Boolean)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static boolean exists(final File file)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
       {
-         public Object run()
+         public Boolean run()
          {
             return file.exists();
          }
       };
-      return (Boolean)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static void mkdirs(final File file)
@@ -247,37 +309,37 @@
 
    public static boolean renameTo(final File srcFile, final File dstfile)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<Boolean> action = new PrivilegedAction<Boolean>()
       {
-         public Object run()
+         public Boolean run()
          {
             return new Boolean(srcFile.renameTo(dstfile));
          }
       };
-      return (Boolean)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static File file(final String pathname)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<File> action = new PrivilegedAction<File>()
       {
-         public Object run()
+         public File run()
          {
             return new File(pathname);
          }
       };
-      return (File)AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 
    public static String[] list(final File file)
    {
-      PrivilegedAction<Object> action = new PrivilegedAction<Object>()
+      PrivilegedAction<String[]> action = new PrivilegedAction<String[]>()
       {
-         public Object run()
+         public String[] run()
          {
             return file.list();
          }
       };
-      return (String[])AccessController.doPrivileged(action);
+      return AccessController.doPrivileged(action);
    }
 }

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/BufferedDecoder.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/BufferedDecoder.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/xml/BufferedDecoder.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.jcr.impl.xml;
 
 import org.apache.ws.commons.util.Base64;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -26,7 +27,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -129,6 +129,7 @@
    /**
     * @return string representation for buffer
     */
+   @Override
    public String toString()
    {
       if (out instanceof ByteArrayOutputStream)
@@ -178,7 +179,7 @@
       byte[] data = ((ByteArrayOutputStream)out).toByteArray();
       fileBuffer = File.createTempFile("decoderBuffer", ".tmp");
       fileBuffer.deleteOnExit();
-      out = new BufferedOutputStream(new FileOutputStream(fileBuffer), bufferSize);
+      out = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(fileBuffer), bufferSize);
       out.write(data);
    }
 
@@ -195,6 +196,7 @@
     * @exception IOException
     *              if an I/O error occurs.
     */
+   @Override
    protected void writeBuffer(byte[] buffer, int start, int length) throws IOException
    {
       if (out instanceof ByteArrayOutputStream)

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportDocView.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.core.value.BinaryValue;
 import org.exoplatform.services.jcr.impl.util.StringConverter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.NodeList;
@@ -30,7 +31,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Calendar;
@@ -69,6 +69,7 @@
       super();
    }
 
+   @Override
    public void initRepository() throws RepositoryException
    {
 
@@ -93,6 +94,7 @@
 
    }
 
+   @Override
    public void tearDown() throws Exception
    {
       log.debug(">> get rootNode on TD START");
@@ -182,7 +184,7 @@
       session.save();
       File destFile = File.createTempFile("multyValueExportStream", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportDocumentView(testNode.getPath(), outStream, false, false);
       outStream.close();
 
@@ -253,7 +255,7 @@
       session.save();
       File destFile = File.createTempFile("multyValueExportStream", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
 
       SAXTransformerFactory saxFact = (SAXTransformerFactory)SAXTransformerFactory.newInstance();
       TransformerHandler handler = saxFact.newTransformerHandler();
@@ -333,7 +335,7 @@
 
       File destFile = File.createTempFile("docLockNodeExport", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
 
       session.exportDocumentView(firstNode.getPath(), outStream, false, false);
       outStream.close();
@@ -352,9 +354,9 @@
    {
 
       Session newSession = repository.login(this.credentials /*
-                                                                           * session.getCredentials
-                                                                           * ()
-                                                                           */);
+                                                                                * session.getCredentials
+                                                                                * ()
+                                                                                */);
 
       newSession.setNamespacePrefix("newjcr", "http://www.jcp.org/jcr/1.0");
 
@@ -381,9 +383,9 @@
    {
 
       Session newSession = repository.login(this.credentials /*
-                                                                           * session.getCredentials
-                                                                           * ()
-                                                                           */);
+                                                                                * session.getCredentials
+                                                                                * ()
+                                                                                */);
       newSession.setNamespacePrefix("newjcr", "http://www.jcp.org/jcr/1.0");
 
       Node testNode = newSession.getRootNode().addNode("jcr:testExportNamespaceRemaping");

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportImport.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportImport.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportImport.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -18,11 +18,11 @@
  */
 package org.exoplatform.services.jcr.api.exporting;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.xml.sax.SAXException;
 
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Calendar;
@@ -66,7 +66,7 @@
       session.save();
       File destFile = File.createTempFile("testWorkspaceExportImportValuesSysView", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportWorkspaceSystemView(outStream, false, false);
       outStream.close();
 
@@ -119,7 +119,7 @@
 
       File destFile = File.createTempFile("testExportImportValuesSysView", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportSystemView(file.getPath(), outStream, false, false);
       outStream.close();
 
@@ -143,7 +143,7 @@
       session.save();
       File destFile = File.createTempFile("testExportImportValuesSysView", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportSystemView(testNode.getPath(), outStream, false, false);
       outStream.close();
 
@@ -358,7 +358,7 @@
       Node exportNode = parentNode.getNode(nodeName);
       File destFile = File.createTempFile("testExportImport", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
 
       if (isSystemView)
       {

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/exporting/TestExportSysView.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -21,6 +21,7 @@
 import org.apache.ws.commons.util.Base64;
 import org.exoplatform.services.jcr.impl.Constants;
 import org.exoplatform.services.jcr.impl.util.StringConverter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.w3c.dom.Document;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
@@ -28,7 +29,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.Calendar;
@@ -170,7 +170,7 @@
       session.save();
       File destFile = File.createTempFile("testExportReferenceableNodes", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportSystemView(testNode.getPath(), outStream, false, false);
       outStream.close();
 
@@ -219,7 +219,7 @@
 
       File destFile = File.createTempFile("sysLockNodeExport", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
 
       session.exportSystemView(firstNode.getPath(), outStream, false, false);
       outStream.close();
@@ -254,7 +254,7 @@
 
       session.save();
       File destFile = File.createTempFile("xmlTest", ".xml");
-      OutputStream outputStream2 = new FileOutputStream(destFile);
+      OutputStream outputStream2 = PrivilegedFileHelper.fileOutputStream(destFile);
 
       SAXTransformerFactory saxFact = (SAXTransformerFactory)TransformerFactory.newInstance();
       TransformerHandler handler = saxFact.newTransformerHandler();
@@ -315,7 +315,7 @@
       session.save();
       File destFile = File.createTempFile("sysMultyValueExportStream", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportSystemView(testNode.getPath(), outStream, false, false);
       outStream.close();
 
@@ -369,7 +369,7 @@
       session.save();
       File destFile = File.createTempFile("multyValueExportStreamSkipBinary", ".xml");
       destFile.deleteOnExit();
-      OutputStream outStream = new FileOutputStream(destFile);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(destFile);
       session.exportSystemView(testNode.getPath(), outStream, true, false);
       outStream.close();
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/AbstractImportTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/AbstractImportTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/AbstractImportTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.core.ExtendedSession;
 import org.exoplatform.services.jcr.core.ExtendedWorkspace;
 import org.exoplatform.services.jcr.impl.core.nodetype.NodeTypeManagerImpl;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.util.IdGenerator;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -326,7 +327,7 @@
    {
       ExtendedSession extendedSession = (ExtendedSession)rootNode.getSession();
 
-      OutputStream outStream = new FileOutputStream(content);
+      OutputStream outStream = PrivilegedFileHelper.fileOutputStream(content);
       if (isSystemView)
       {
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/importing/TestSystemViewImport.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.ext.action.InvocationContext;
 import org.exoplatform.services.jcr.core.ExtendedSession;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.impl.xml.importing.ContentImporter;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -252,7 +253,7 @@
 
       File tmp = File.createTempFile("__exojcr_TestSysView__", ".tmp");
 
-      OutputStream xmlOut = new FileOutputStream(tmp);
+      OutputStream xmlOut = PrivilegedFileHelper.fileOutputStream(tmp);
       sysview.getSession().exportSystemView(ref.getPath(), xmlOut, false, false);
       xmlOut.close();
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/cluster/BaseClusteringFunctionalTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -19,6 +19,7 @@
 import junit.framework.TestCase;
 
 import org.exoplatform.services.jcr.cluster.JCRWebdavConnection;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -55,6 +56,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
@@ -79,6 +81,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    protected void tearDown() throws Exception
    {
       super.tearDown();
@@ -111,7 +114,7 @@
       byte[] data = new byte[1024]; // 1Kb
 
       File testFile = File.createTempFile(prefix, ".tmp");
-      FileOutputStream tempOut = new FileOutputStream(testFile);
+      FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
       Random random = new Random();
 
       for (int i = 0; i < sizeInKb; i++)

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRestoreWorkspaceInitializer.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRestoreWorkspaceInitializer.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestRestoreWorkspaceInitializer.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.JcrImplBaseTest;
 import org.exoplatform.services.jcr.core.CredentialsImpl;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -73,7 +74,7 @@
       f.renameTo(new File("./sv_export_binary.bin"));
 
       File outf = new File("./sv_export_root.xml");
-      FileOutputStream out = new FileOutputStream(outf);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(outf);
       session.exportWorkspaceSystemView(out, false, false);
       out.close();
    }
@@ -97,7 +98,7 @@
       {
          InputStream is =
             ws1root.getProperty("1_common/cargo/cargo/0.5/cargo-0.5.jar/jcr:content/jcr:data").getStream();
-         FileOutputStream fout = new FileOutputStream("./cargo-0.5.jar");
+         FileOutputStream fout = PrivilegedFileHelper.fileOutputStream("./cargo-0.5.jar");
          int r = -1;
          byte[] b = new byte[1024];
          while ((r = is.read(b)) >= 0)

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestSVNodeDataOptimization.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -32,6 +32,7 @@
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.config.WorkspaceInitializerEntry;
 import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 /**
  * Created by The eXo Platform SAS.
@@ -42,15 +43,14 @@
  * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
  * @version $Id$
  */
-public class TestSVNodeDataOptimization
-   extends JcrImplBaseTest
+public class TestSVNodeDataOptimization extends JcrImplBaseTest
 {
-   
+
    @Override
    public void setUp() throws Exception
    {
       super.setUp();
-      SessionImpl ses = (SessionImpl) repository.login(credentials, "ws1");
+      SessionImpl ses = (SessionImpl)repository.login(credentials, "ws1");
       if (ses != null)
       {
          try
@@ -86,7 +86,7 @@
    @Override
    protected void tearDown() throws Exception
    {
-      SessionImpl ses = (SessionImpl) repository.login(credentials, "ws1");
+      SessionImpl ses = (SessionImpl)repository.login(credentials, "ws1");
       if (ses != null)
       {
          try
@@ -124,7 +124,7 @@
    {
 
       //ADD content
-      SessionImpl ses = (SessionImpl) repository.login(credentials, "ws1");
+      SessionImpl ses = (SessionImpl)repository.login(credentials, "ws1");
 
       //Add node with sub name sibling
       Node nodeSNS = ses.getRootNode().addNode("node_with_sns");
@@ -146,16 +146,16 @@
       File backup = File.createTempFile("full-backup", ".xml");
       backup.deleteOnExit();
 
-      ses.exportWorkspaceSystemView(new FileOutputStream(backup), false, false);
+      ses.exportWorkspaceSystemView(PrivilegedFileHelper.fileOutputStream(backup), false, false);
 
       // restore to ws1_restored
       WorkspaceEntry ws1_restore =
-               makeWorkspaceEntry("ws1_restored", isMultiDB(session) ? "jdbcjcr2export3" : "jdbcjcr", backup, ses);
+         makeWorkspaceEntry("ws1_restored", isMultiDB(session) ? "jdbcjcr2export3" : "jdbcjcr", backup, ses);
       repository.configWorkspace(ws1_restore);
       repository.createWorkspace(ws1_restore.getName());
 
       // check
-      SessionImpl backupSession = (SessionImpl) repository.login(credentials, "ws1_restored");
+      SessionImpl backupSession = (SessionImpl)repository.login(credentials, "ws1_restored");
 
       assertNotNull(backupSession);
 
@@ -164,8 +164,8 @@
 
    private void checkEquals(SessionImpl expected, SessionImpl actual) throws Exception
    {
-      NodeImpl srcNode = (NodeImpl) expected.getRootNode();
-      NodeImpl destNode = (NodeImpl) actual.getRootNode();
+      NodeImpl srcNode = (NodeImpl)expected.getRootNode();
+      NodeImpl destNode = (NodeImpl)actual.getRootNode();
 
       checkNodeEquals(srcNode, destNode);
    }
@@ -174,7 +174,7 @@
    {
       assertTrue(dest.equals(src));
       assertEquals(src.getIndex(), dest.getIndex());
-      assertEquals(((NodeData) src.getData()).getOrderNumber(), ((NodeData) dest.getData()).getOrderNumber());
+      assertEquals(((NodeData)src.getData()).getOrderNumber(), ((NodeData)dest.getData()).getOrderNumber());
 
       NodeIterator srcIterator = src.getNodes();
       NodeIterator destIterator = dest.getNodes();
@@ -182,16 +182,16 @@
       assertEquals(srcIterator.getSize(), destIterator.getSize());
 
       while (srcIterator.hasNext())
-         checkNodeEquals((NodeImpl) srcIterator.nextNode(), (NodeImpl) destIterator.nextNode());
+         checkNodeEquals((NodeImpl)srcIterator.nextNode(), (NodeImpl)destIterator.nextNode());
    }
 
    private WorkspaceEntry makeWorkspaceEntry(String name, String sourceName, File sysViewFile, SessionImpl ses)
    {
-      WorkspaceEntry ws1e = (WorkspaceEntry) ses.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
+      WorkspaceEntry ws1e = (WorkspaceEntry)ses.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
 
       WorkspaceEntry ws1back = new WorkspaceEntry();
       ws1back.setName(name);
-      ws1back.setUniqueName(((RepositoryImpl) ses.getRepository()).getName() + "_" + ws1back.getName());
+      ws1back.setUniqueName(((RepositoryImpl)ses.getRepository()).getName() + "_" + ws1back.getName());
 
       ws1back.setAccessManager(ws1e.getAccessManager());
       ws1back.setAutoInitializedRootNt(ws1e.getAutoInitializedRootNt());
@@ -206,7 +206,7 @@
 
       List<SimpleParameterEntry> wieParams = new ArrayList<SimpleParameterEntry>();
       wieParams
-               .add(new SimpleParameterEntry(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, sysViewFile.getPath()));
+         .add(new SimpleParameterEntry(SysViewWorkspaceInitializer.RESTORE_PATH_PARAMETER, sysViewFile.getPath()));
 
       wiEntry.setParameters(wieParams);
 
@@ -216,14 +216,14 @@
       ArrayList qParams = new ArrayList();
       qParams.add(new SimpleParameterEntry("indexDir", "target" + File.separator + name));
       QueryHandlerEntry qEntry =
-               new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
+         new QueryHandlerEntry("org.exoplatform.services.jcr.impl.core.query.lucene.SearchIndex", qParams);
 
       ws1back.setQueryHandler(qEntry);
 
       ArrayList params = new ArrayList();
       for (Iterator i = ws1back.getContainer().getParameters().iterator(); i.hasNext();)
       {
-         SimpleParameterEntry p = (SimpleParameterEntry) i.next();
+         SimpleParameterEntry p = (SimpleParameterEntry)i.next();
          SimpleParameterEntry newp = new SimpleParameterEntry(p.getName(), p.getValue());
 
          if (isMultiDB(ses) && newp.getName().equals("source-name"))
@@ -237,7 +237,7 @@
       }
 
       ContainerEntry ce =
-               new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer", params);
+         new ContainerEntry("org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer", params);
       ws1back.setContainer(ce);
 
       return ws1back;
@@ -245,11 +245,11 @@
 
    private boolean isMultiDB(SessionImpl session)
    {
-      WorkspaceEntry ws1e = (WorkspaceEntry) session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
+      WorkspaceEntry ws1e = (WorkspaceEntry)session.getContainer().getComponentInstanceOfType(WorkspaceEntry.class);
 
       for (Iterator i = ws1e.getContainer().getParameters().iterator(); i.hasNext();)
       {
-         SimpleParameterEntry p = (SimpleParameterEntry) i.next();
+         SimpleParameterEntry p = (SimpleParameterEntry)i.next();
          SimpleParameterEntry newp = new SimpleParameterEntry(p.getName(), p.getValue());
 
          if (newp.getName().equals("multi-db"))
@@ -257,7 +257,7 @@
       }
 
       throw new RuntimeException("Can not get property 'multi-db' in configuration on workspace '" + ws1e.getName()
-               + "'");
+         + "'");
    }
 
 }

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/TestWorkspaceRestore.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -23,6 +23,7 @@
 import org.exoplatform.services.jcr.config.RepositoryConfigurationException;
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.util.ConfigurationHelper;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -69,7 +70,7 @@
 
       File content = File.createTempFile("data", ".xml");
       content.deleteOnExit();
-      OutputStream os = new BufferedOutputStream(new FileOutputStream(content));
+      OutputStream os = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(content));
       defSession.exportSystemView(defRoot.getPath(), os, false, false);
       os.close();
       defSession.logout();
@@ -137,7 +138,7 @@
 
       File content = File.createTempFile("data", ".xml");
       content.deleteOnExit();
-      OutputStream os = new BufferedOutputStream(new FileOutputStream(content));
+      OutputStream os = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(content));
       defSession.exportSystemView(node1.getPath(), os, false, false);
       os.close();
       defSession.logout();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestFileBasedNamespaceMappings.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestFileBasedNamespaceMappings.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/core/query/lucene/TestFileBasedNamespaceMappings.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -17,6 +17,8 @@
 
 package org.exoplatform.services.jcr.impl.core.query.lucene;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+
 import junit.framework.TestCase;
 
 import java.io.File;
@@ -49,6 +51,7 @@
       assertEquals("mix", namereg.getNamespacePrefixByURI("http://www.jcp.org/jcr/mix/1.0"));
    }
 
+   @Override
    public void setUp() throws Exception
    {
       test_mapp = File.createTempFile("temp", "mapping");
@@ -67,12 +70,13 @@
       props.setProperty("xs", "http://www.w3.org/2001/XMLSchema");
       props.setProperty("fn", "http://www.w3.org/2004/10/xpath-functions");
 
-      props.store(new FileOutputStream(test_mapp), "");
+      props.store(PrivilegedFileHelper.fileOutputStream(test_mapp), "");
 
       props.clear();
       test_mapp.deleteOnExit();
    }
 
+   @Override
    protected void tearDown() throws Exception
    {
       test_mapp.delete();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -25,6 +25,7 @@
 import java.io.ObjectOutputStream;
 
 import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 /**
  * Created by The eXo Platform SAS.
@@ -35,17 +36,16 @@
  * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
  * @version $Id$
  */
-public class TestByteArrayPersistedValueDataSerialization
-   extends JcrImplBaseTest
+public class TestByteArrayPersistedValueDataSerialization extends JcrImplBaseTest
 {
    public void testBAPVDSerialization() throws Exception
    {
-    
-      byte []buf = new byte[124578];
-      
-      for (int i = 0; i< buf.length; i++)
-         buf[i] = (byte) (Math.random()*256);
-      
+
+      byte[] buf = new byte[124578];
+
+      for (int i = 0; i < buf.length; i++)
+         buf[i] = (byte)(Math.random() * 256);
+
       // Create ValueData instants
       ByteArrayPersistedValueData vd = new ByteArrayPersistedValueData(11, buf);
 
@@ -53,21 +53,21 @@
       out.deleteOnExit();
 
       //serialize
-      ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+      ObjectOutputStream oos = new ObjectOutputStream(PrivilegedFileHelper.fileOutputStream(out));
       oos.writeObject(vd);
       oos.flush();
       oos.close();
 
       //deserialize
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
-      ByteArrayPersistedValueData deserializedValueData = (ByteArrayPersistedValueData) ois.readObject();
+      ByteArrayPersistedValueData deserializedValueData = (ByteArrayPersistedValueData)ois.readObject();
 
       //check
       assertNotNull(deserializedValueData);
       assertEquals(vd.getLength(), deserializedValueData.getLength());
       assertEquals(vd.getOrderNumber(), deserializedValueData.getOrderNumber());
-      
+
       for (int j = 0; j < vd.getAsByteArray().length; j++)
-        assertEquals(vd.getAsByteArray()[j], deserializedValueData.getAsByteArray()[j]);
+         assertEquals(vd.getAsByteArray()[j], deserializedValueData.getAsByteArray()[j]);
    }
 }

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCleanableFileStreamValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCleanableFileStreamValueData.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestCleanableFileStreamValueData.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -21,6 +21,7 @@
 import org.exoplatform.services.jcr.JcrImplBaseTest;
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 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.SwapFile;
 
 import java.io.File;
@@ -86,7 +87,7 @@
       testCleaner = new FileCleaner(CLEANER_TIMEOUT);
 
       SwapFile sf = SwapFile.get(parentDir, FILE_NAME);
-      FileOutputStream fout = new FileOutputStream(sf);
+      FileOutputStream fout = PrivilegedFileHelper.fileOutputStream(sf);
       fout.write("testFileCleaned".getBytes());
       fout.close();
       sf.spoolDone();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationLogTestLoad.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationLogTestLoad.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationLogTestLoad.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
 import org.exoplatform.services.jcr.impl.core.NodeImpl;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -68,7 +69,7 @@
       long jcrread = 0;
 
       File jcrfile = File.createTempFile("jcr", "test");
-      ObjectWriterImpl jcrout = new ObjectWriterImpl(new FileOutputStream(jcrfile));
+      ObjectWriterImpl jcrout = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(jcrfile));
 
       System.out.println(" WRITE START");
       long t1 = System.currentTimeMillis();
@@ -89,7 +90,7 @@
       for (int i = 0; i < iter; i++)
       {
          TransactionChangesLogReader rdr = new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder);
-         TransactionChangesLog obj = (TransactionChangesLog)rdr.read(jcrin);
+         TransactionChangesLog obj = rdr.read(jcrin);
 
          //  readed.add(obj); 
       }
@@ -108,7 +109,7 @@
         long javaRead = 0;
 
         File jfile = File.createTempFile("java", "test");
-        ObjectOutputStream jout = new ObjectOutputStream(new FileOutputStream(jfile));
+        ObjectOutputStream jout = new ObjectOutputStream(PrivilegedFileHelper.fileOutputStream(jfile));
 
         it = logs.iterator();
         

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationVSJavaSerializationTestLoad.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationVSJavaSerializationTestLoad.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JCRSerializationVSJavaSerializationTestLoad.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -75,7 +76,7 @@
          it = list.iterator();
 
          File jcrfile = File.createTempFile("jcr", "test");
-         ObjectWriterImpl jcrout = new ObjectWriterImpl(new FileOutputStream(jcrfile));
+         ObjectWriterImpl jcrout = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(jcrfile));
 
          long t1 = System.currentTimeMillis();
          PersistedValueDataWriter wr = new PersistedValueDataWriter();
@@ -112,7 +113,7 @@
       for (int j = 0; j < iterations; j++)
       {
          File jfile = File.createTempFile("java", "test");
-         ObjectOutputStream jout = new ObjectOutputStream(new FileOutputStream(jfile));
+         ObjectOutputStream jout = new ObjectOutputStream(PrivilegedFileHelper.fileOutputStream(jfile));
 
          it = list.iterator();
          long t2 = System.currentTimeMillis();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/JcrImplSerializationBaseTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -46,6 +46,7 @@
 import org.exoplatform.services.jcr.datamodel.ValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.StreamPersistedValueData;
 import org.exoplatform.services.jcr.impl.storage.value.fs.operations.ValueFileIOHelper;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.storage.value.ValueIOChannel;
 
 /**
@@ -104,7 +105,7 @@
    protected File serializeLogs(List<TransactionChangesLog> logs) throws IOException, UnknownClassIdException
    {
       File jcrfile = File.createTempFile("jcr", "test");
-      ObjectWriterImpl jcrout = new ObjectWriterImpl(new FileOutputStream(jcrfile));
+      ObjectWriterImpl jcrout = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(jcrfile));
 
       TransactionChangesLogWriter wr = new TransactionChangesLogWriter();
       for (TransactionChangesLog tcl : logs)
@@ -129,7 +130,7 @@
          while (true)
          {
             TransactionChangesLog obj =
-               (TransactionChangesLog)(new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
+               (new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
             // TransactionChangesLog obj = new TransactionChangesLog();
             // obj.readObject(jcrin);
             readed.add(obj);
@@ -139,8 +140,7 @@
       {
          // ok
       }
-      
-      
+
       //Imitation of save.
       imitationSave(readed);
 
@@ -159,34 +159,37 @@
       for (TransactionChangesLog tLog : readed)
       {
          ChangesLogIterator it = tLog.getLogIterator();
-         
-         while (it.hasNextLog()) 
+
+         while (it.hasNextLog())
          {
             PlainChangesLog pLog = it.nextLog();
-            
+
             for (ItemState state : pLog.getAllStates())
             {
                ItemData itemData = state.getData();
-               
+
                if (!itemData.isNode())
                {
                   PropertyData propData = (PropertyData)itemData;
-                  
-                  for(ValueData valueData : propData.getValues())
+
+                  for (ValueData valueData : propData.getValues())
                   {
-                     if (valueData instanceof StreamPersistedValueData) {
+                     if (valueData instanceof StreamPersistedValueData)
+                     {
                         // imitation of JCR save
-                        if (((StreamPersistedValueData) valueData).getTempFile() != null)
+                        if (((StreamPersistedValueData)valueData).getTempFile() != null)
                         {
-                         ((StreamPersistedValueData) valueData).setPersistedFile(((StreamPersistedValueData) valueData).getTempFile());
+                           ((StreamPersistedValueData)valueData).setPersistedFile(((StreamPersistedValueData)valueData)
+                              .getTempFile());
                         }
                         else
                         {
                            File file = File.createTempFile("tempFile", "tmp");
                            file.deleteOnExit();
-                           
-                           copy(((StreamPersistedValueData) valueData).getStream(), new FileOutputStream(file));
-                           ((StreamPersistedValueData) valueData).setPersistedFile(file);
+
+                           copy(((StreamPersistedValueData)valueData).getStream(), PrivilegedFileHelper
+                              .fileOutputStream(file));
+                           ((StreamPersistedValueData)valueData).setPersistedFile(file);
                         }
                      }
                   }
@@ -195,7 +198,7 @@
          }
       }
    }
-   
+
    protected long copy(InputStream in, OutputStream out) throws IOException
    {
       // compare classes as in Java6 Channels.newChannel(), Java5 has a bug in newChannel().

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/MultipleDeserializationTestLoad.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/MultipleDeserializationTestLoad.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/MultipleDeserializationTestLoad.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -25,6 +25,7 @@
 import org.exoplatform.services.jcr.dataflow.persistent.ItemsPersistenceListener;
 import org.exoplatform.services.jcr.impl.core.NodeImpl;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -126,7 +127,7 @@
 
       // Serialize with JCR
       File jcrfile = File.createTempFile("jcr", "test");
-      ObjectWriterImpl jcrout = new ObjectWriterImpl(new FileOutputStream(jcrfile));
+      ObjectWriterImpl jcrout = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(jcrfile));
       TransactionChangesLog l = pl.pushChanges().get(0);
       TransactionChangesLogWriter wr = new TransactionChangesLogWriter();
       wr.write(jcrout, l);
@@ -136,7 +137,7 @@
       ObjectReaderImpl jcrin = new ObjectReaderImpl(new FileInputStream(jcrfile));
       long jcrfread = System.currentTimeMillis();
       TransactionChangesLog mlog =
-         (TransactionChangesLog)(new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
+         (new TransactionChangesLogReader(fileCleaner, maxBufferSize, holder)).read(jcrin);
       //TransactionChangesLog mlog = new TransactionChangesLog();
       //mlog.readObject(jcrin);
       jcrfread = System.currentTimeMillis() - jcrfread;
@@ -151,7 +152,7 @@
          // deserialize
          jcrin = new ObjectReaderImpl(new FileInputStream(jcrfile));
          long t3 = System.currentTimeMillis();
-         TransactionChangesLog log = (TransactionChangesLog)rdr.read(jcrin);
+         TransactionChangesLog log = rdr.read(jcrin);
 
          t3 = System.currentTimeMillis() - t3;
          jcrread += t3;

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestEOFException.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestEOFException.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestEOFException.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,6 +20,7 @@
 
 import org.exoplatform.services.jcr.dataflow.serialization.ObjectReader;
 import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.EOFException;
 import java.io.File;
@@ -42,7 +43,7 @@
       final byte[] buffer = createBLOBTempData(45);
 
       File test = File.createTempFile("testEOF", "");
-      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));
+      ObjectWriter ow = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(test));
 
       ow.write(buffer);
       ow.close();
@@ -72,7 +73,7 @@
    {
 
       File test = File.createTempFile("testEOF", "");
-      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));
+      ObjectWriter ow = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(test));
 
       ow.writeBoolean(true);
       ow.close();
@@ -101,7 +102,7 @@
    {
 
       File test = File.createTempFile("testEOF", "");
-      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));
+      ObjectWriter ow = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(test));
 
       ow.writeInt(24);
       ow.close();
@@ -131,7 +132,7 @@
    {
 
       File test = File.createTempFile("testEOF", "");
-      ObjectWriter ow = new ObjectWriterImpl(new FileOutputStream(test));
+      ObjectWriter ow = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(test));
 
       ow.writeLong(24);
       ow.close();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/serialization/TestJCRSerializationVersionRestore.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.jcr.impl.dataflow.serialization;
 
 import org.exoplatform.services.jcr.dataflow.TransactionChangesLog;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -97,9 +98,9 @@
       tempFile2.deleteOnExit();
       tempFile3.deleteOnExit();
 
-      FileOutputStream fos = new FileOutputStream(tempFile);
-      FileOutputStream fos2 = new FileOutputStream(tempFile2);
-      FileOutputStream fos3 = new FileOutputStream(tempFile3);
+      FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
+      FileOutputStream fos2 = PrivilegedFileHelper.fileOutputStream(tempFile2);
+      FileOutputStream fos3 = PrivilegedFileHelper.fileOutputStream(tempFile3);
 
       String content = "this is the content #1";
       String content2 = "this is the content #2_";

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/ValueStoragePluginTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/ValueStoragePluginTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/ValueStoragePluginTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -25,6 +25,7 @@
 import org.exoplatform.services.jcr.config.WorkspaceEntry;
 import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
 import org.exoplatform.services.jcr.impl.storage.jdbc.JDBCWorkspaceDataContainer;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.util.ConfigurationHelper;
 import org.exoplatform.services.jcr.util.IdGenerator;
 import org.exoplatform.services.log.ExoLogger;
@@ -229,7 +230,7 @@
       byte[] data = new byte[1024]; // 1Kb
 
       File testFile = File.createTempFile(IdGenerator.generate(), ".tmp");
-      FileOutputStream tempOut = new FileOutputStream(testFile);
+      FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
       Random random = new Random();
 
       for (int i = 0; i < sizeInb; i += 1024)

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileIOChannel.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -24,6 +24,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.TesterTransientValueData;
 import org.exoplatform.services.jcr.impl.storage.value.ValueDataResourceHolder;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -75,7 +76,7 @@
       file.deleteOnExit();
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 
@@ -84,7 +85,7 @@
       file = new File(rootDir, "testReadFromIOChannel1");
       if (file.exists())
          file.delete();
-      out = new FileOutputStream(file);
+      out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileValueIO.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileValueIO.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/TestFileValueIO.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -25,6 +25,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.persistent.ByteArrayPersistedValueData;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
 import org.exoplatform.services.jcr.impl.storage.value.ValueDataResourceHolder;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -87,7 +88,7 @@
       File file = new File("target/testReadByteArrayValueData");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 
@@ -109,7 +110,7 @@
       File file = new File("target/testReadFileValueData");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/TestValueFileIOHelper.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/TestValueFileIOHelper.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/TestValueFileIOHelper.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -23,6 +23,7 @@
 import org.exoplatform.services.jcr.dataflow.serialization.ObjectWriter;
 import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectReaderImpl;
 import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.BufferedInputStream;
 import java.io.File;
@@ -85,6 +86,7 @@
 
    private boolean outFile;
 
+   @Override
    public void setUp() throws Exception
    {
       super.setUp();
@@ -102,7 +104,7 @@
          srcSerialization = File.createTempFile("srcSerialization", ".tmp");
          srcSerialization.deleteOnExit();
 
-         OutputStream out = new FileOutputStream(srcSerialization);
+         OutputStream out = PrivilegedFileHelper.fileOutputStream(srcSerialization);
          ObjectWriter ow = new ObjectWriterImpl(out);
          for (int i = 0; i < BLOCK_COUNT; i++)
          {
@@ -127,6 +129,7 @@
       dest = File.createTempFile("vdftest", "", testDir);
    }
 
+   @Override
    public void tearDown() throws Exception
    {
       dest.delete();
@@ -143,7 +146,7 @@
       long start = System.currentTimeMillis();
 
       InputStream in = new FileInputStream(srcSerialization);
-      OutputStream out = new FileOutputStream(dest);
+      OutputStream out = PrivilegedFileHelper.fileOutputStream(dest);
 
       ObjectReader or = new ObjectReaderImpl(in);
       ObjectWriter ow = new ObjectWriterImpl(out);
@@ -177,7 +180,7 @@
       start = System.currentTimeMillis();
 
       in = new BufferedInputStream(new FileInputStream(srcSerialization));
-      out = new FileOutputStream(dest);
+      out = PrivilegedFileHelper.fileOutputStream(dest);
       openChannel(in, out);
 
       long pos = 0;
@@ -207,7 +210,7 @@
    public void testCopyFileToFile() throws Exception
    {
 
-      io.copyClose(new FileInputStream(src), new FileOutputStream(dest));
+      io.copyClose(new FileInputStream(src), PrivilegedFileHelper.fileOutputStream(dest));
 
       // check length
       assertEquals(src.length(), dest.length());
@@ -233,7 +236,7 @@
 
       InputStream in = new FileInputStream(src);
       // InputStream in = new URL("http://jboss1.exoua-int:8089/browser/02.zip").openStream();
-      OutputStream out = new FileOutputStream(dest);
+      OutputStream out = PrivilegedFileHelper.fileOutputStream(dest);
       try
       {
          int r = 0;
@@ -258,7 +261,7 @@
 
       // copy via NIO
       start = System.currentTimeMillis();
-      io.copyClose(new BufferedInputStream(new FileInputStream(src)), new FileOutputStream(dest));
+      io.copyClose(new BufferedInputStream(new FileInputStream(src)), PrivilegedFileHelper.fileOutputStream(dest));
       // io.copyClose(new URL("http://jboss1.exoua-int:8089/browser/02.zip").openStream(), new
       // FileOutputStream(dest));
       System.out.println("\t=== NIO time " + (System.currentTimeMillis() - start));

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/tools/tree/generator/RandomValueNodeGenerator.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/tools/tree/generator/RandomValueNodeGenerator.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/tools/tree/generator/RandomValueNodeGenerator.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.jcr.impl.tools.tree.generator;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.util.IdGenerator;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
@@ -176,7 +177,7 @@
       byte[] data = new byte[1024]; // 1Kb
 
       File testFile = File.createTempFile("randomsizefile", ".tmp");
-      FileOutputStream tempOut = new FileOutputStream(testFile);
+      FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
 
       for (int i = 0; i < sizeInb; i += 1024)
       {

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestPersistedValueData.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -25,6 +25,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.persistent.FilePersistedValueData;
 import org.exoplatform.services.jcr.impl.storage.value.fs.Probe;
 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.SwapFile;
 
 import java.io.ByteArrayInputStream;
@@ -60,7 +61,7 @@
       File file = new File("target/testCreateFileStreamValueData");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 
@@ -87,7 +88,7 @@
       //File file = new File("target/testIfFinalizeRemovesTempFileStreamValueData");
       //if (file.exists())
       //  file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 
@@ -113,7 +114,7 @@
       File file = new File("target/testConcurrentFileStreamValueDataReading");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       // approx. 10Kb file
       for (int i = 0; i < 100; i++)
       {

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueData.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -26,6 +26,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 import org.exoplatform.services.jcr.impl.util.JCRDateFormat;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -71,12 +72,13 @@
       File file = new File("target/testCreateFileStreamTransientValueData");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 
       FileInputStream fs1 = new FileInputStream(file);
-      TransientValueData vd = new TransientValueData(0, null, fs1, null, new FileCleaner(), 5, new File("target"), true);
+      TransientValueData vd =
+         new TransientValueData(0, null, fs1, null, new FileCleaner(), 5, new File("target"), true);
 
       // spool to file
       InputStream fs2 = vd.getAsStream();
@@ -118,7 +120,7 @@
       // TODO not influenced here as will be spooled to byte array anyway
       //vd.setMaxBufferSize(5);
       //vd.setFileCleaner(new FileCleaner());
-      
+
       //
       InputStream fs2 = vd.getAsStream();
       assertEquals(10, vd.getLength());

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueDataSpooling.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueDataSpooling.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestTransientValueDataSpooling.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -29,6 +29,7 @@
 import org.exoplatform.services.jcr.impl.core.NodeImpl;
 import org.exoplatform.services.jcr.impl.dataflow.serialization.ObjectWriterImpl;
 import org.exoplatform.services.jcr.impl.dataflow.serialization.TransactionChangesLogWriter;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -82,6 +83,7 @@
    /**
     * {@inheritDoc}
     */
+   @Override
    public void tearDown() throws Exception
    {
       super.tearDown();
@@ -178,7 +180,8 @@
       node.getProperty("testProp").remove();
       session.save();
 
-      ObjectWriter out = new ObjectWriterImpl(new FileOutputStream(File.createTempFile("out", ".tmp")));
+      ObjectWriter out =
+         new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(File.createTempFile("out", ".tmp")));
       TransactionChangesLogWriter lw = new TransactionChangesLogWriter();
 
       lw.write(out, cl);

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/impl/value/TestValueImpl.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -28,6 +28,7 @@
 import org.exoplatform.services.jcr.impl.core.value.StringValue;
 import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -55,7 +56,7 @@
       File file = new File("target/testNewBinaryValue");
       if (file.exists())
          file.delete();
-      FileOutputStream out = new FileOutputStream(file);
+      FileOutputStream out = PrivilegedFileHelper.fileOutputStream(file);
       out.write(buf);
       out.close();
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/java/TestFileLock.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/java/TestFileLock.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/lab/java/TestFileLock.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.services.jcr.lab.java;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
+
 import junit.framework.TestCase;
 
 import java.io.File;
@@ -45,7 +47,7 @@
 
       File f = new File("\\\\storm\\public\\file1.tmp");
       f.createNewFile();
-      FileOutputStream fout = new FileOutputStream(f);
+      FileOutputStream fout = PrivilegedFileHelper.fileOutputStream(f);
       FileChannel fc = fout.getChannel();
 
       ByteBuffer buff = ByteBuffer.wrap("test-file1".getBytes());
@@ -65,7 +67,7 @@
          System.out.println(new String(b, 0, res));
 
       // lock file
-      fout = new FileOutputStream(f);
+      fout = PrivilegedFileHelper.fileOutputStream(f);
       fc = fout.getChannel();
       FileLock lock = fc.lock();
 
@@ -74,12 +76,13 @@
       // check another lock
       Thread another = new Thread()
       {
+         @Override
          public void run()
          {
             try
             {
                Thread.sleep(25);
-               FileOutputStream fout1 = new FileOutputStream(new File("\\\\storm\\public\\file1.tmp"));
+               FileOutputStream fout1 = PrivilegedFileHelper.fileOutputStream(new File("\\\\storm\\public\\file1.tmp"));
                FileChannel fc1 = fout1.getChannel();
                try
                {
@@ -135,7 +138,7 @@
       File f = new File("D:\\tmp\\file2.tmp");
 
       System.out.println("Try open file for write " + System.currentTimeMillis());
-      FileOutputStream fout = new FileOutputStream(f);
+      FileOutputStream fout = PrivilegedFileHelper.fileOutputStream(f);
       FileChannel fc = fout.getChannel();
       System.out.println("Try lock file " + System.currentTimeMillis());
       FileLock lock = fc.lock();
@@ -172,7 +175,7 @@
       // lock file for write
       Thread.sleep(timeout);
       System.out.println("Try open file for write " + System.currentTimeMillis());
-      fout = new FileOutputStream(f);
+      fout = PrivilegedFileHelper.fileOutputStream(f);
       fc = fout.getChannel();
       System.out.println("Try lock file " + System.currentTimeMillis());
       lock = fc.lock();
@@ -219,7 +222,7 @@
 
       // write new content
       System.out.println("Try open file for write " + System.currentTimeMillis());
-      FileOutputStream fout = new FileOutputStream(f);
+      FileOutputStream fout = PrivilegedFileHelper.fileOutputStream(f);
       FileChannel fc = fout.getChannel();
       System.out.println("Try lock file " + System.currentTimeMillis());
       FileLock lock = fc.lock();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestExportBigFiles.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestExportBigFiles.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestExportBigFiles.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -19,6 +19,7 @@
 package org.exoplatform.services.jcr.load.blob;
 
 import org.exoplatform.services.jcr.JcrAPIBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
@@ -73,7 +74,7 @@
       // Exporting repository content
       File file = File.createTempFile("tesSysExport", ".xml");
 
-      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(file));
       session.exportSystemView(testLocalBigFiles.getPath(), bufferedOutputStream, false, false);
       bufferedOutputStream.flush();
       bufferedOutputStream.close();
@@ -137,7 +138,7 @@
       // Exporting repository content
       File file = File.createTempFile("tesDocExport", ".xml");
 
-      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(file));
       session.exportDocumentView(testLocalBigFiles.getPath(), bufferedOutputStream, false, false);
       bufferedOutputStream.flush();
       bufferedOutputStream.close();
@@ -197,7 +198,7 @@
       // Exporting repository content
       File file = File.createTempFile("tesSysExport", ".xml");
 
-      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(file));
       session.exportSystemView(testLocalBigFiles.getPath(), bufferedOutputStream, false, false);
       bufferedOutputStream.flush();
       bufferedOutputStream.close();
@@ -267,7 +268,7 @@
       // Exporting repository content
       File file = File.createTempFile("tesSysExport", ".xml");
 
-      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file));
+      BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(file));
       session.exportSystemView(testLocalBigFiles.getPath(), bufferedOutputStream, false, false);
       bufferedOutputStream.flush();
       bufferedOutputStream.close();
@@ -301,13 +302,14 @@
 
    }
 
+   @Override
    protected File createBLOBTempFile(int sizeInb) throws IOException
    {
       // create test file
       byte[] data = new byte[1024]; // 1Kb
 
       File testFile = File.createTempFile("exportImportFileTest", ".tmp");
-      FileOutputStream tempOut = new FileOutputStream(testFile);
+      FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
       Random random = new Random();
 
       for (int i = 0; i < sizeInb; i += 1024)

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestLoadRepo.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestLoadRepo.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/blob/TestLoadRepo.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -24,6 +24,7 @@
 import org.exoplatform.services.jcr.impl.tools.tree.ValueSsh1Comparator;
 import org.exoplatform.services.jcr.impl.tools.tree.ValueSsh1Generator;
 import org.exoplatform.services.jcr.impl.tools.tree.generator.RandomValueNodeGenerator;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
@@ -60,7 +61,7 @@
    {
       Node testNode = root.addNode("testNode");
       File checkSummValue = new File(System.getProperty("java.io.tmpdir"), "repo.ssh1");
-      BufferedOutputStream sshStrream = new BufferedOutputStream(new FileOutputStream(checkSummValue));
+      BufferedOutputStream sshStrream = new BufferedOutputStream(PrivilegedFileHelper.fileOutputStream(checkSummValue));
       RandomValueNodeGenerator nodeGenerator =
          new RandomValueNodeGenerator(session.getValueFactory(), 6, 5, 8, 5, 1024 * 1024);
       TreeGenerator generator = new TreeGenerator(testNode, nodeGenerator);
@@ -70,7 +71,7 @@
       ((NodeImpl)testNode).getData().accept(ssh1Generator);
       sshStrream.close();
       File exportFile = new File(System.getProperty("java.io.tmpdir"), "testExport.xml");
-      OutputStream os = new FileOutputStream(exportFile);
+      OutputStream os = PrivilegedFileHelper.fileOutputStream(exportFile);
       session.exportSystemView(testNode.getPath(), os, false, false);
       os.close();
    }

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestPerformance.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestPerformance.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/perf/TestPerformance.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -515,7 +515,7 @@
    // byte[] data = new byte[BUFFER_SIZE]; // 1KB
    // Arrays.fill(data, (byte) SYMBOL); // symbol A
    // File testFile = File.createTempFile(prefix, ".tmp");
-   // FileOutputStream tempOut = new FileOutputStream(testFile);
+   // FileOutputStream tempOut = PrivilegedFileHelper.fileOutputStream(testFile);
    // for (int i = 0; i < sizeInKb; i++) {
    // tempOut.write(data);
    // }

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/fs/TestFSReadWrite.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/fs/TestFSReadWrite.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/load/storage/fs/TestFSReadWrite.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -20,6 +20,7 @@
 
 import junit.framework.TestCase;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.util.SIDGenerator;
 
 import java.io.File;
@@ -105,6 +106,7 @@
 
    }
 
+   @Override
    protected void setUp() throws Exception
    {
       super.setUp();
@@ -114,6 +116,7 @@
       testRoot.deleteOnExit();
    }
 
+   @Override
    protected void tearDown() throws Exception
    {
       long time = System.currentTimeMillis();
@@ -185,7 +188,7 @@
          try
          {
             // f.createNewFile();
-            FileOutputStream fos = new FileOutputStream(f);
+            FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(f);
             try
             {
                fos.write(("File content " + f.getAbsolutePath()).getBytes());
@@ -216,7 +219,7 @@
          try
          {
             // f.createNewFile();
-            FileOutputStream fos = new FileOutputStream(f);
+            FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(f);
             try
             {
                fos.write(("File content " + f.getAbsolutePath()).getBytes());
@@ -258,7 +261,7 @@
          try
          {
             // f.createNewFile();
-            FileOutputStream fos = new FileOutputStream(f);
+            FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(f);
             try
             {
                fos.write(("File content " + f.getAbsolutePath()).getBytes());
@@ -304,7 +307,7 @@
          try
          {
             // f.createNewFile();
-            FileOutputStream fos = new FileOutputStream(f);
+            FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(f);
             try
             {
                fos.write(("File content " + f.getAbsolutePath()).getBytes());
@@ -347,7 +350,7 @@
          File f = new File(dir.getAbsolutePath() + File.separator + fileName);
          try
          {
-            FileOutputStream fos = new FileOutputStream(f);
+            FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(f);
             try
             {
                fos.write(("qazws").getBytes());

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/RemoveVDTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/RemoveVDTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/RemoveVDTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -30,6 +30,7 @@
 import org.exoplatform.services.jcr.impl.dataflow.serialization.PersistedValueDataReader;
 import org.exoplatform.services.jcr.impl.dataflow.serialization.PersistedValueDataWriter;
 import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 
 import java.io.File;
 import java.io.FileInputStream;
@@ -57,7 +58,7 @@
 
       File serf = File.createTempFile("serialization", "test");
 
-      ObjectWriter wr = new ObjectWriterImpl(new FileOutputStream(serf));
+      ObjectWriter wr = new ObjectWriterImpl(PrivilegedFileHelper.fileOutputStream(serf));
 
       PersistedValueDataWriter vdw = new PersistedValueDataWriter();
       vdw.write(wr, vd);
@@ -83,7 +84,7 @@
 
       or.close();
       // Imitation save
-      ((StreamPersistedValueData) vd1).setPersistedFile(((StreamPersistedValueData) vd1).getTempFile());
+      ((StreamPersistedValueData)vd1).setPersistedFile(((StreamPersistedValueData)vd1).getTempFile());
 
       // read second time
       or = new ObjectReaderImpl(new FileInputStream(serf));
@@ -99,7 +100,7 @@
       }
       or.close();
       // Imitation save
-      ((StreamPersistedValueData) vd2).setPersistedFile(((StreamPersistedValueData) vd2).getTempFile());
+      ((StreamPersistedValueData)vd2).setPersistedFile(((StreamPersistedValueData)vd2).getTempFile());
 
       assertTrue(vd1.getFile().exists());
       assertTrue(vd2.getFile().exists());

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/TestExportImportAmongSessions.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/TestExportImportAmongSessions.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/common/TestExportImportAmongSessions.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.jcr.usecases.common;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.usecases.BaseUsecasesTest;
 
 import java.io.ByteArrayInputStream;
@@ -67,7 +68,7 @@
       File outputFile = File.createTempFile("jcr_bin_test-", ".tmp");
       outputFile.deleteOnExit();
 
-      session1.exportDocumentView(testNode.getPath(), new FileOutputStream(outputFile), false, false);
+      session1.exportDocumentView(testNode.getPath(), PrivilegedFileHelper.fileOutputStream(outputFile), false, false);
 
       testNode.remove();
       session1.save();
@@ -116,7 +117,7 @@
       File outputFile = File.createTempFile("jcr_bin_test", ".tmp");
       outputFile.deleteOnExit();
 
-      session2.exportDocumentView(testNode.getPath(), new FileOutputStream(outputFile), false, false);
+      session2.exportDocumentView(testNode.getPath(), PrivilegedFileHelper.fileOutputStream(outputFile), false, false);
 
       testNode.remove();
       session2.save();

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/export/ExportWorkspaceSystemViewTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/export/ExportWorkspaceSystemViewTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/export/ExportWorkspaceSystemViewTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -27,6 +27,7 @@
 import org.exoplatform.services.jcr.impl.core.RepositoryImpl;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
 import org.exoplatform.services.jcr.impl.core.SysViewWorkspaceInitializer;
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.usecases.BaseUsecasesTest;
 
 import java.io.File;
@@ -56,7 +57,7 @@
 
          // 1-st export
          File f1 = new File("target/1.xml");
-         sessionWS1.exportWorkspaceSystemView(new FileOutputStream(f1), false, false);
+         sessionWS1.exportWorkspaceSystemView(PrivilegedFileHelper.fileOutputStream(f1), false, false);
 
          // 1-st import
          WorkspaceEntry ws1_restore_1 =
@@ -77,7 +78,7 @@
          // 2-st export
          SessionImpl back1 = (SessionImpl)repository.login(credentials, "ws1_restore_1");
          File f2 = new File("target/2.xml");
-         back1.exportWorkspaceSystemView(new FileOutputStream(f2), false, false);
+         back1.exportWorkspaceSystemView(PrivilegedFileHelper.fileOutputStream(f2), false, false);
 
          // 2-st import
          WorkspaceEntry ws1_restore_2 =

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/version/FileRestoreTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/version/FileRestoreTest.java	2010-06-14 07:35:22 UTC (rev 2562)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/usecases/version/FileRestoreTest.java	2010-06-14 07:38:11 UTC (rev 2563)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.jcr.usecases.version;
 
+import org.exoplatform.services.jcr.impl.util.io.PrivilegedFileHelper;
 import org.exoplatform.services.jcr.usecases.BaseUsecasesTest;
 
 import java.io.File;
@@ -50,9 +51,9 @@
       tempFile2.deleteOnExit();
       tempFile3.deleteOnExit();
 
-      FileOutputStream fos = new FileOutputStream(tempFile);
-      FileOutputStream fos2 = new FileOutputStream(tempFile2);
-      FileOutputStream fos3 = new FileOutputStream(tempFile3);
+      FileOutputStream fos = PrivilegedFileHelper.fileOutputStream(tempFile);
+      FileOutputStream fos2 = PrivilegedFileHelper.fileOutputStream(tempFile2);
+      FileOutputStream fos3 = PrivilegedFileHelper.fileOutputStream(tempFile3);
 
       String content = "this is the content #1";
       String content2 = "this is the content #2_";



More information about the exo-jcr-commits mailing list