Search in sources :

Example 11 with OMemoryStream

use of com.orientechnologies.orient.core.serialization.OMemoryStream in project orientdb by orientechnologies.

the class OSQLQuery method fromStream.

public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException {
    final OMemoryStream buffer = new OMemoryStream(iStream);
    queryFromStream(buffer);
    return this;
}
Also used : OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream)

Example 12 with OMemoryStream

use of com.orientechnologies.orient.core.serialization.OMemoryStream in project orientdb by orientechnologies.

the class TrackedListTest method testSerialization.

/**
   * Test that {@link OTrackedList} is serialised correctly.
   */
@Test
public void testSerialization() throws Exception {
    class NotSerializableDocument extends ODocument {

        private static final long serialVersionUID = 1L;

        private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
        }
    }
    final OTrackedList<String> beforeSerialization = new OTrackedList<String>(new NotSerializableDocument());
    beforeSerialization.add("firstVal");
    beforeSerialization.add("secondVal");
    final OMemoryStream memoryStream = new OMemoryStream();
    ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();
    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked") final List<String> afterSerialization = (List<String>) input.readObject();
    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "List size");
    for (int i = 0; i < afterSerialization.size(); i++) {
        Assert.assertEquals(afterSerialization.get(i), beforeSerialization.get(i));
    }
}
Also used : OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) ObjectOutputStream(java.io.ObjectOutputStream) NotSerializableException(java.io.NotSerializableException) ArrayList(java.util.ArrayList) List(java.util.List) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 13 with OMemoryStream

use of com.orientechnologies.orient.core.serialization.OMemoryStream in project orientdb by orientechnologies.

the class TrackedSetTest method testSetSerialization.

/**
   * Test that {@link OTrackedSet} is serialised correctly.
   */
@Test
public void testSetSerialization() throws Exception {
    class NotSerializableDocument extends ODocument {

        private static final long serialVersionUID = 1L;

        private void writeObject(ObjectOutputStream oos) throws IOException {
            throw new NotSerializableException();
        }
    }
    final OTrackedSet<String> beforeSerialization = new OTrackedSet<String>(new NotSerializableDocument());
    beforeSerialization.add("firstVal");
    beforeSerialization.add("secondVal");
    final OMemoryStream memoryStream = new OMemoryStream();
    ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();
    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked") final Set<String> afterSerialization = (Set<String>) input.readObject();
    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "Set size");
    Assert.assertTrue(beforeSerialization.containsAll(afterSerialization));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) OMemoryInputStream(com.orientechnologies.orient.core.serialization.OMemoryInputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) ObjectOutputStream(java.io.ObjectOutputStream) NotSerializableException(java.io.NotSerializableException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Example 14 with OMemoryStream

use of com.orientechnologies.orient.core.serialization.OMemoryStream in project orientdb by orientechnologies.

the class BinarySerializationStream method main.

public static void main(String[] args) {
    long time = System.currentTimeMillis();
    ByteArrayOutputStream s = new ByteArrayOutputStream();
    try {
        DataOutputStream str = new DataOutputStream(s);
        for (int i = 0; i < 1000000; i++) {
            str.writeBytes("adfsdfsdfadfsdfsdfadfsdfsdfadfsdfsdf");
            str.writeInt(32);
            str.writeLong(32);
            str.writeByte(32);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("Data Output Stream " + (System.currentTimeMillis() - time));
    time = System.currentTimeMillis();
    OMemoryStream mou = new OMemoryStream();
    for (int i = 0; i < 1000000; i++) {
        mou.setCustom("adfsdfsdfadfsdfsdfadfsdfsdfadfsdfsdf");
        mou.set(32);
        mou.set(32l);
        mou.set((byte) 32);
    }
    System.out.println("OMemoryStream " + (System.currentTimeMillis() - time));
    System.out.println("" + s.toByteArray().length + " " + mou.toByteArray().length);
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream)

Aggregations

OMemoryStream (com.orientechnologies.orient.core.serialization.OMemoryStream)14 IOException (java.io.IOException)4 ObjectOutputStream (java.io.ObjectOutputStream)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3 NotSerializableException (java.io.NotSerializableException)3 ObjectInputStream (java.io.ObjectInputStream)3 Test (org.testng.annotations.Test)3 OInterruptedException (com.orientechnologies.common.concur.lock.OInterruptedException)1 OLockException (com.orientechnologies.common.concur.lock.OLockException)1 OException (com.orientechnologies.common.exception.OException)1 OIOException (com.orientechnologies.common.io.OIOException)1 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 SocketException (java.net.SocketException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1