Examples of OSerializableStream


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

  public StringBuilder toStream(final ODatabaseComplex<?> iDatabase, final StringBuilder iOutput, Object iValue) {
    if (iValue != null) {
            if (!(iValue instanceof OSerializableStream))
                throw new OSerializationException("Can't serialize the object since it's not implements the OSerializableStream interface");

      OSerializableStream stream = (OSerializableStream) iValue;
      iOutput.append(iValue.getClass().getName());
      iOutput.append(OStreamSerializerHelper.SEPARATOR);
      iOutput.append(OBinaryProtocol.bytes2string(stream.toStream()));
    }
    return iOutput;
  }
View Full Code Here

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

        iValue = ((ODocumentSerializable) iValue).toDocument();

      if (!(iValue instanceof OSerializableStream))
        throw new OSerializationException("Cannot serialize the object since it's not implements the OSerializableStream interface");

      OSerializableStream stream = (OSerializableStream) iValue;
      iOutput.append(iValue.getClass().getName());
      iOutput.append(OStreamSerializerHelper.SEPARATOR);
      iOutput.append(OBinaryProtocol.bytes2string(stream.toStream()));
    }

    return iOutput;
  }
View Full Code Here

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

  public Object fromStream(final String iStream) {
    if (iStream == null || iStream.length() == 0)
      // NULL VALUE
      return null;

    OSerializableStream instance = null;

    int propertyPos = iStream.indexOf(':');
    int pos = iStream.indexOf(OStreamSerializerHelper.SEPARATOR);
    if (pos < 0 || propertyPos > -1 && pos > propertyPos) {
      instance = new ODocument();
      pos = -1;
    } else {
      final String className = iStream.substring(0, pos);
      try {
        final Class<?> clazz = Class.forName(className);
        instance = (OSerializableStream) clazz.newInstance();
      } catch (Exception e) {
        OLogManager.instance().error(this, "Error on unmarshalling content. Class: " + className, e, OSerializationException.class);
      }
    }

    instance.fromStream(OBase64Utils.decode(iStream.substring(pos + 1)));
    return instance;
  }
View Full Code Here

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

      break;
    case CUSTOM:
      try {
        String className = readString(bytes);
        Class<?> clazz = Class.forName(className);
        OSerializableStream stream = (OSerializableStream) clazz.newInstance();
        stream.fromStream(readBinary(bytes));
        value = stream;
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
      break;
View Full Code Here

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

  public StringBuilder toStream(final StringBuilder iOutput, Object iValue) {
    if (iValue != null) {
      if (!(iValue instanceof OSerializableStream))
        throw new OSerializationException("Cannot serialize the object since it's not implements the OSerializableStream interface");

      OSerializableStream stream = (OSerializableStream) iValue;
      iOutput.append(iValue.getClass().getName());
      iOutput.append(OStreamSerializerHelper.SEPARATOR);
      iOutput.append(OBase64Utils.encodeBytes(stream.toStream()));
    }
    return iOutput;
  }
View Full Code Here

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

          OSerializationException.class);

    final String className = OBinaryProtocol.bytes2string(iStream, 4, classNameSize);

    try {
      final OSerializableStream stream;
      // CHECK FOR ALIASES
      if (className.equalsIgnoreCase("q"))
        // QUERY
        stream = new OSQLSynchQuery<Object>();
      else if (className.equalsIgnoreCase("c"))
        // SQL COMMAND
        stream = new OCommandSQL();
      else if (className.equalsIgnoreCase("s"))
        // SCRIPT COMMAND
        stream = new OCommandScript();
      else
        // CREATE THE OBJECT BY INVOKING THE EMPTY CONSTRUCTOR
        stream = (OSerializableStream) Class.forName(className).newInstance();

      return stream.fromStream(OArrays.copyOfRange(iStream, 4 + classNameSize, iStream.length));

    } catch (Exception e) {
      OLogManager.instance().error(this, "Error on unmarshalling content. Class: " + className, e, OSerializationException.class);
    }
    return null;
View Full Code Here

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

    if (!(iObject instanceof OSerializableStream))
      throw new OSerializationException("Cannot serialize the object [" + iObject.getClass() + ":" + iObject
          + "] since it does not implement the OSerializableStream interface");

    OSerializableStream stream = (OSerializableStream) iObject;

    // SERIALIZE THE CLASS NAME
    final byte[] className;
    if (iObject instanceof OQuery<?>)
      className = QUERY_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandSQL)
      className = SQL_COMMAND_CLASS_ASBYTES;
    else if (iObject instanceof OCommandScript)
      className = SCRIPT_COMMAND_CLASS_ASBYTES;
    else
      className = OBinaryProtocol.string2bytes(iObject.getClass().getName());

    // SERIALIZE THE OBJECT CONTENT
    byte[] objectContent = stream.toStream();

    byte[] result = new byte[4 + className.length + objectContent.length];

    // COPY THE CLASS NAME SIZE + CLASS NAME + OBJECT CONTENT
    System.arraycopy(OBinaryProtocol.int2bytes(className.length), 0, result, 0, 4);
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.