[exo-jcr-commits] exo-jcr SVN: r930 - in jcr/branches/1.12.0-JBC/component/core/src: test/java/org/exoplatform/services/jcr/impl/dataflow and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Dec 7 05:11:19 EST 2009


Author: sergiykarpenko
Date: 2009-12-07 05:11:19 -0500 (Mon, 07 Dec 2009)
New Revision: 930

Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
   jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
Log:
EXOJCR-264: absolute blob file path now serialized with TransientValueData

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2009-12-07 08:41:44 UTC (rev 929)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/TransientValueData.java	2009-12-07 10:11:19 UTC (rev 930)
@@ -950,6 +950,10 @@
     */
    public void writeExternal(ObjectOutput out) throws IOException
    {
+      //spool if needed
+      if (!spooled)
+         spoolInputStream();
+
       if (this.isByteArray())
       {
          out.writeInt(1);
@@ -962,21 +966,24 @@
          // write streams
          out.writeInt(2);
          //TODO Need optimization in backup service.
-         byte[] buf = new byte[4 * 1024];
+         //byte[] buf = new byte[4 * 1024];
 
-         if (!spooled)
-            spoolInputStream();
-         InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
-         long dataLength = (spoolFile == null ? data.length : spoolFile.length());
-         int len;
+         // write path to spool file
+         String filePath = spoolFile.getAbsolutePath();
 
-         //write length of spoolFile
-         out.writeLong(dataLength);
+         out.writeUTF(filePath);
 
-         while ((len = in.read(buf)) > 0)
-            out.write(buf, 0, len);
+         //         InputStream in = (spoolFile == null ? new ByteArrayInputStream(data) : new FileInputStream(spoolFile));
+         //         long dataLength = (spoolFile == null ? data.length : spoolFile.length());
+         //         int len;
 
-         in.close();
+         //         write length of spoolFile
+         //         out.writeLong(dataLength);
+
+         //         while ((len = in.read(buf)) > 0)
+         //            out.write(buf, 0, len);
+         //
+         //         in.close();
       }
 
       out.writeInt(orderNumber);
@@ -997,32 +1004,42 @@
       }
       else
       {
-         //read file form stream
-         long lengthSpoolFile = in.readLong();
+         String path = in.readUTF();
 
-         //TODO May be optimization.
-         SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
-         sf.acquire(this);
-         OutputStream outStream = new FileOutputStream(sf);
+         //TODO we do not know is there SpoolFile or TreeFile etc.
+         File sf = new File(path);
 
-         byte[] buf = new byte[4 * 1024];
-
-         while (lengthSpoolFile > 0)
+         if (!sf.exists())
          {
-            if (lengthSpoolFile - buf.length > 0)
-            {
-               in.readFully(buf);
-               outStream.write(buf);
-            }
-            else
-            {
-               in.readFully(buf, 0, (int)lengthSpoolFile);
-               outStream.write(buf, 0, (int)lengthSpoolFile);
-            }
-            lengthSpoolFile -= buf.length;
+            //TODO this exception must be never thrown
+            throw new IOException("SpoolFile [" + sf.getAbsolutePath() + "] not exist.");
          }
-         outStream.flush();
-         outStream.close();
+         //read file form stream
+         //         long lengthSpoolFile = in.readLong();
+         //
+         //         //TODO May be optimization.
+         //         SpoolFile sf = SpoolFile.createTempFile("jcrvd", null, tempDirectory);
+         //         sf.acquire(this);
+         //         OutputStream outStream = new FileOutputStream(sf);
+         //
+         //         byte[] buf = new byte[4 * 1024];
+         //
+         //         while (lengthSpoolFile > 0)
+         //         {
+         //            if (lengthSpoolFile - buf.length > 0)
+         //            {
+         //               in.readFully(buf);
+         //               outStream.write(buf);
+         //            }
+         //            else
+         //            {
+         //               in.readFully(buf, 0, (int)lengthSpoolFile);
+         //               outStream.write(buf, 0, (int)lengthSpoolFile);
+         //            }
+         //            lengthSpoolFile -= buf.length;
+         //         }
+         //         outStream.flush();
+         //         outStream.close();
          spoolFile = sf;
          spooled = true;
       }

Modified: jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java	2009-12-07 08:41:44 UTC (rev 929)
+++ jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java	2009-12-07 10:11:19 UTC (rev 930)
@@ -18,15 +18,15 @@
  */
 package org.exoplatform.services.jcr.impl.dataflow;
 
+import org.exoplatform.services.jcr.JcrImplBaseTest;
+import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
-import org.exoplatform.services.jcr.JcrImplBaseTest;
-import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
-
 /**
  * Created by The eXo Platform SAS.
  * 
@@ -36,8 +36,7 @@
  * @author <a href="mailto:alex.reshetnyak at exoplatform.com.ua">Alex Reshetnyak</a>
  * @version $Id$
  */
-public class TestTransientValueDataSerialization
-   extends JcrImplBaseTest
+public class TestTransientValueDataSerialization extends JcrImplBaseTest
 {
 
    public void testTVDSerialization() throws Exception
@@ -47,9 +46,8 @@
 
       // Create TransientValueData instants
       TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
-      tvd.setMaxBufferSize(200*1024);
+      tvd.setMaxBufferSize(200 * 1024);
       tvd.setFileCleaner(new FileCleaner());
-      
 
       File out = File.createTempFile("test", ".data");
       out.deleteOnExit();
@@ -62,7 +60,7 @@
 
       //deserialize
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
-      TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+      TransientValueData deserializedTransientValueData = (TransientValueData)ois.readObject();
 
       //check
       assertNotNull(deserializedTransientValueData);
@@ -70,15 +68,18 @@
       assertEquals(tvd.getOrderNumber(), deserializedTransientValueData.getOrderNumber());
       compareStream(tvd.getAsStream(), deserializedTransientValueData.getAsStream());
    }
-   
+
    public void testTVDSerialization2M() throws Exception
    {
       File f = createBLOBTempFile(2145);
       f.deleteOnExit();
 
       // Create TransientValueData instants
-      TransientValueData tvd = new TransientValueData(new FileInputStream(f), 10);
-      tvd.setMaxBufferSize(200*1024);
+      TransientValueData tvd = //new TransientValueData(new FileInputStream(f), 10);
+         new TransientValueData(10, null, new FileInputStream(f), null, null, 1024, new File(System
+            .getProperty("java.io.tmpdir")), false);
+
+      tvd.setMaxBufferSize(200 * 1024);
       tvd.setFileCleaner(new FileCleaner());
 
       File out = File.createTempFile("test", ".data");
@@ -92,7 +93,7 @@
 
       //deserialize
       ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
-      TransientValueData deserializedTransientValueData = (TransientValueData) ois.readObject();
+      TransientValueData deserializedTransientValueData = (TransientValueData)ois.readObject();
 
       //check
       assertNotNull(deserializedTransientValueData);



More information about the exo-jcr-commits mailing list