Examples of OMemoryStream


Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

  @Override
  public byte[] compress(final byte[] content, final int offset, final int length) {
    try {
      final byte[] result;
      final OMemoryStream memoryOutputStream = new OMemoryStream();
      final GZIPOutputStream gzipOutputStream = new GZIPOutputStream(memoryOutputStream, 16384); // 16KB
      try {
        gzipOutputStream.write(content, offset, length);
        gzipOutputStream.finish();
        result = memoryOutputStream.toByteArray();
      } finally {
        gzipOutputStream.close();
      }

      return result;
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

public abstract class OZIPCompression extends OAbstractCompression {
  @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;
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

   *          Input Stream, use buffered input stream wrapper to speed up reading
   * @return Buffer read from the stream. It's also the internal buffer size in bytes
   * @throws IOException
   */
  public int fromInputStream(final InputStream in) throws IOException {
    final OMemoryStream out = new OMemoryStream();
    try {
      final byte[] buffer = new byte[OMemoryStream.DEF_SIZE];
      int readBytesCount;
      while (true) {
        readBytesCount = in.read(buffer, 0, buffer.length);
        if (readBytesCount == -1) {
          break;
        }
        out.write(buffer, 0, readBytesCount);
      }
      out.flush();
      _source = out.toByteArray();
    } finally {
      out.close();
    }
    _size = _source.length;
    return _size;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    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++) {
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

     channel.writeByte((byte) 0);
   }

   private void serializeExceptionObject(Throwable original) throws IOException {
     try {
       final OMemoryStream memoryStream = new OMemoryStream();
       final ObjectOutputStream objectOutputStream = new ObjectOutputStream(memoryStream);

       objectOutputStream.writeObject(original);
       objectOutputStream.flush();

       final byte[] result = memoryStream.toByteArray();
       objectOutputStream.close();

       channel.writeBytes(result);
     } catch (Exception e) {
       OLogManager.instance().warn(this, "Can't serialize an exception object", e);
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    final OTrackedMap<String> beforeSerialization = new OTrackedMap<String>(new NotSerializableDocument());
    beforeSerialization.put(0, "firstVal");
    beforeSerialization.put(1, "secondVal");

    final OMemoryStream memoryStream = new OMemoryStream();
    final ObjectOutputStream out = new ObjectOutputStream(memoryStream);
    out.writeObject(beforeSerialization);
    out.close();

    final ObjectInputStream input = new ObjectInputStream(new OMemoryInputStream(memoryStream.copy()));
    @SuppressWarnings("unchecked")
    final Map<Object, String> afterSerialization = (Map<Object, String>) input.readObject();

    Assert.assertEquals(afterSerialization.size(), beforeSerialization.size(), "Map size");
    for (int i = 0; i < afterSerialization.size(); i++) {
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    return false;
  }

  @Override
  protected OMemoryStream queryToStream() {
    final OMemoryStream buffer = super.queryToStream();

    buffer.setUtf8(nextPageRID != null ? nextPageRID.toString() : "");

    final byte[] queryParams = serializeQueryParameters(previousQueryParams);
    buffer.set(queryParams);

    return buffer;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    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));
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    return setDirty();
  }

  public OSerializableStream fromStream(final byte[] iStream) throws OSerializationException {
    if (stream == null)
      stream = new OMemoryStream(iStream);
    else
      stream.setSource(iStream);

    treeSize = stream.jump(OFFSET_TREESIZE).getAsInteger();
    size = stream.jump(OFFSET_NODESIZE).getAsInteger();
View Full Code Here

Examples of com.orientechnologies.orient.core.serialization.OMemoryStream

    return this;
  }

  public byte[] toStream() throws OSerializationException {
    if (stream == null)
      stream = new OMemoryStream();

    try {
      stream.jump(OFFSET_TREESIZE).set(treeSize);
      stream.jump(OFFSET_NODESIZE).set(size);
      stream.jump(OFFSET_COLOR).set(color);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.