[exo-jcr-commits] exo-jcr SVN: r2553 - in jcr/trunk/exo.jcr.component.core/src: main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jun 11 07:35:33 EDT 2010


Author: tolusha
Date: 2010-06-11 07:35:31 -0400 (Fri, 11 Jun 2010)
New Revision: 2553

Modified:
   jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.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/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
   jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestUpdate.java
Log:
EXOJCR-756:fix some bugs

Modified: jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java	2010-06-11 10:02:18 UTC (rev 2552)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/StreamPersistedValueData.java	2010-06-11 11:35:31 UTC (rev 2553)
@@ -188,32 +188,32 @@
          {
             if (file != null)
             {
-               return file.length();
+               return new Long(file.length());
             }
             else if (tempFile != null)
             {
-               return tempFile.length();
+               return new Long(tempFile.length());
             }
             else if (stream instanceof FileInputStream)
             {
                try
                {
-                  return ((FileInputStream)stream).getChannel().size();
+                  return new Long(((FileInputStream)stream).getChannel().size());
                }
                catch (IOException e)
                {
-                  return -1;
+                  return new Long(-1);
                }
             }
             else
             {
                try
                {
-                  return stream.available();
+                  return new Long(stream.available());
                }
                catch (IOException e)
                {
-                  return -1;
+                  return new Long(-1);
                }
             }
          }

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-11 10:02:18 UTC (rev 2552)
+++ jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/value/fs/operations/ValueFileIOHelper.java	2010-06-11 11:35:31 UTC (rev 2553)
@@ -75,36 +75,61 @@
     * @throws IOException
     *           if error
     */
-   protected ValueData readValue(File file, int orderNum, int maxBufferSize) throws IOException
+   protected ValueData readValue(final File file, final int orderNum, final int maxBufferSize) throws IOException
    {
+      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      {
+         public Object run() throws Exception
+         {
+            long fileSize = file.length();
 
-      long fileSize = file.length();
-
-      if (fileSize > maxBufferSize)
+            if (fileSize > maxBufferSize)
+            {
+               return new FilePersistedValueData(orderNum, file);
+            }
+            else
+            {
+               FileInputStream is = new FileInputStream(file);
+               try
+               {
+                  int buffSize = (int)fileSize;
+                  byte[] res = new byte[buffSize];
+                  int rpos = 0;
+                  int r = -1;
+                  byte[] buff = new byte[IOBUFFER_SIZE > buffSize ? IOBUFFER_SIZE : buffSize];
+                  while ((r = is.read(buff)) >= 0)
+                  {
+                     System.arraycopy(buff, 0, res, rpos, r);
+                     rpos += r;
+                  }
+                  return new ByteArrayPersistedValueData(orderNum, res);
+               }
+               finally
+               {
+                  is.close();
+               }
+            }
+         }
+      };
+      try
       {
-         return new FilePersistedValueData(orderNum, file);
+         return (ValueData)AccessController.doPrivileged(action);
       }
-      else
+      catch (PrivilegedActionException pae)
       {
-         FileInputStream is = new FileInputStream(file);
-         try
+         Throwable cause = pae.getCause();
+         if (cause instanceof IOException)
          {
-            int buffSize = (int)fileSize;
-            byte[] res = new byte[buffSize];
-            int rpos = 0;
-            int r = -1;
-            byte[] buff = new byte[IOBUFFER_SIZE > buffSize ? IOBUFFER_SIZE : buffSize];
-            while ((r = is.read(buff)) >= 0)
-            {
-               System.arraycopy(buff, 0, res, rpos, r);
-               rpos += r;
-            }
-            return new ByteArrayPersistedValueData(orderNum, res);
+            throw (IOException)cause;
          }
-         finally
+         else if (cause instanceof RuntimeException)
          {
-            is.close();
+            throw (RuntimeException)cause;
          }
+         else
+         {
+            throw new RuntimeException(cause);
+         }
       }
    }
 
@@ -140,16 +165,44 @@
     * @throws IOException
     *           if error occurs
     */
-   protected void writeByteArrayValue(File file, ValueData value) throws IOException
+   protected void writeByteArrayValue(final File file, final ValueData value) throws IOException
    {
-      OutputStream out = new FileOutputStream(file);
+      PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
+      {
+         public Object run() throws Exception
+         {
+            OutputStream out = new FileOutputStream(file);
+            try
+            {
+               out.write(value.getAsByteArray());
+            }
+            finally
+            {
+               out.close();
+            }
+
+            return null;
+         }
+      };
       try
       {
-         out.write(value.getAsByteArray());
+         AccessController.doPrivileged(action);
       }
-      finally
+      catch (PrivilegedActionException pae)
       {
-         out.close();
+         Throwable cause = pae.getCause();
+         if (cause instanceof IOException)
+         {
+            throw (IOException)cause;
+         }
+         else if (cause instanceof RuntimeException)
+         {
+            throw (RuntimeException)cause;
+         }
+         else
+         {
+            throw new RuntimeException(cause);
+         }
       }
    }
 

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2010-06-11 10:02:18 UTC (rev 2552)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/BaseStandaloneTest.java	2010-06-11 11:35:31 UTC (rev 2553)
@@ -395,7 +395,13 @@
 
    protected File createBLOBTempFile(int sizeInKb) throws IOException
    {
-      return createBLOBTempFile("exo_jcr_test_temp_file_", sizeInKb);
+      System.setSecurityManager(null);
+
+      File file = createBLOBTempFile("exo_jcr_test_temp_file_", sizeInKb);
+
+      System.setSecurityManager(new SecurityManager());
+
+      return file;
    }
 
    protected File createBLOBTempFile(String prefix, int sizeInKb) throws IOException

Modified: jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestUpdate.java
===================================================================
--- jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestUpdate.java	2010-06-11 10:02:18 UTC (rev 2552)
+++ jcr/trunk/exo.jcr.component.core/src/test/java/org/exoplatform/services/jcr/api/writing/TestUpdate.java	2010-06-11 11:35:31 UTC (rev 2553)
@@ -61,7 +61,6 @@
       Node corrNode = (Node)ws1session.getItem(ws1node.getPath());
 
       File propData = createBLOBTempFile(1024);
-      propData.deleteOnExit();
 
       InputStream pds = new FileInputStream(propData);
       try



More information about the exo-jcr-commits mailing list