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