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;
}
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));
}
}
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));
}
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);
}
Aggregations