Search in sources :

Example 6 with OMemoryStream

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

the class OCommandScript method fromStream.

public OSerializableStream fromStream(byte[] iStream) throws OSerializationException {
    final OMemoryStream buffer = new OMemoryStream(iStream);
    language = buffer.getAsString();
    // FIX TO HANDLE USAGE OF EXECUTION MODE STARTING FROM v2.1.3
    final int currPosition = buffer.getPosition();
    final String value = buffer.getAsString();
    try {
        executionMode = OCommandDistributedReplicateRequest.DISTRIBUTED_EXECUTION_MODE.valueOf(value);
    } catch (IllegalArgumentException e) {
        // OLD VERSION: RESET TO THE OLD POSITION
        buffer.setPosition(currPosition);
    }
    fromStream(buffer);
    return this;
}
Also used : OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream)

Example 7 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)

Example 8 with OMemoryStream

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

the class OCommandScript method toStream.

public byte[] toStream() throws OSerializationException {
    final OMemoryStream buffer = new OMemoryStream();
    buffer.setUtf8(language);
    buffer.setUtf8(executionMode.name());
    return toStream(buffer);
}
Also used : OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream)

Example 9 with OMemoryStream

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

the class OGZIPCompression method compress.

@Override
public byte[] compress(final byte[] content, final int offset, final int length) {
    try {
        final byte[] result;
        final OMemoryStream memoryOutputStream = new OMemoryStream();
        // 16KB
        final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(memoryOutputStream, 16384);
        try {
            gzipOutputStream.write(content, offset, length);
            gzipOutputStream.finish();
            result = memoryOutputStream.toByteArray();
        } finally {
            gzipOutputStream.close();
        }
        return result;
    } catch (IOException ioe) {
        throw new IllegalStateException("Exception during data compression", ioe);
    }
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) IOException(java.io.IOException)

Example 10 with OMemoryStream

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

the class OZIPCompression method compress.

@Override
public byte[] compress(final byte[] content, final int offset, final int length) {
    try {
        final byte[] result;
        final OMemoryStream memoryOutputStream = new OMemoryStream();
        final ZipOutputStream zipOutputStream = new ZipOutputStream(memoryOutputStream);
        setLevel(zipOutputStream);
        try {
            ZipEntry ze = new ZipEntry("content");
            zipOutputStream.putNextEntry(ze);
            try {
                zipOutputStream.write(content, offset, length);
            } finally {
                zipOutputStream.closeEntry();
            }
            zipOutputStream.finish();
            result = memoryOutputStream.toByteArray();
        } finally {
            zipOutputStream.close();
        }
        return result;
    } catch (IOException ioe) {
        throw new IllegalStateException("Exception during data compression", ioe);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) OMemoryStream(com.orientechnologies.orient.core.serialization.OMemoryStream) IOException(java.io.IOException)

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