Author: areshetnyak
Date: 2009-11-06 12:08:38 -0500 (Fri, 06 Nov 2009)
New Revision: 496
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java
Log:
EXOJCR-201 :Add serialization mechanism to ByteArrayPersistentValuData and added test
TestByteArrayPersistentValueDataSerialization.
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-06
16:55:26 UTC (rev 495)
+++
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/persistent/ByteArrayPersistedValueData.java 2009-11-06
17:08:38 UTC (rev 496)
@@ -22,8 +22,11 @@
import org.exoplatform.services.jcr.impl.dataflow.TransientValueData;
import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
import java.io.IOException;
import java.io.InputStream;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
import javax.jcr.RepositoryException;
@@ -33,10 +36,18 @@
* @author Gennady Azarenkov
* @version $Id$
*/
-public class ByteArrayPersistedValueData extends AbstractValueData
+public class ByteArrayPersistedValueData extends AbstractValueData implements
Externalizable
{
protected byte[] data;
+
+ /**
+ * Empty constructor to serialization.
+ */
+ public ByteArrayPersistedValueData()
+ {
+ super(0);
+ }
/**
* ByteArrayPersistedValueData constructor.
@@ -108,4 +119,20 @@
return false;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
+ {
+ orderNumber = in.readInt();
+
+ data = new byte[in.readInt()];
+ in.readFully(data);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException
+ {
+ out.writeInt(orderNumber);
+
+ out.writeInt(data.length);
+ out.write(data);
+ }
+
}
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-11-06
16:55:26 UTC (rev 495)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/TestTransientValueDataSerialization.java 2009-11-06
17:08:38 UTC (rev 496)
@@ -52,7 +52,7 @@
File out = File.createTempFile("test", ".data");
- f.deleteOnExit();
+ out.deleteOnExit();
//serialize
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
@@ -82,7 +82,7 @@
tvd.setFileCleaner(new FileCleaner());
File out = File.createTempFile("test", ".data");
- f.deleteOnExit();
+ out.deleteOnExit();
//serialize
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
Added:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
===================================================================
---
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
(rev 0)
+++
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java 2009-11-06
17:08:38 UTC (rev 496)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.dataflow.persistent;
+
+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;
+
+/**
+ * Created by The eXo Platform SAS.
+ *
+ * <br/>
+ * Date: 06.11.2009
+ *
+ * @author <a href="mailto:alex.reshetnyak@exoplatform.com.ua">Alex
Reshetnyak</a>
+ * @version $Id$
+ */
+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);
+
+ // Create ValueData instants
+ ByteArrayPersistedValueData vd = new ByteArrayPersistedValueData(buf, 11);
+
+ File out = File.createTempFile("test", ".data");
+ out.deleteOnExit();
+
+ //serialize
+ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out));
+ oos.writeObject(vd);
+ oos.flush();
+ oos.close();
+
+ //deserialize
+ ObjectInputStream ois = new ObjectInputStream(new FileInputStream(out));
+ 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]);
+ }
+}
Property changes on:
jcr/branches/1.12.0-JBC/component/core/src/test/java/org/exoplatform/services/jcr/impl/dataflow/persistent/TestByteArrayPersistedValueDataSerialization.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native