Ejemplo n.º 1
0
    @Override
    public void writeTo(OutputStream stream, ORecordVersion version) throws IOException {
      final ODistributedVersion distributedVersion = (ODistributedVersion) version;

      OBinaryProtocol.int2bytes(distributedVersion.counter, stream);
      OBinaryProtocol.long2bytes(distributedVersion.timestamp, stream);
      OBinaryProtocol.long2bytes(distributedVersion.macAddress, stream);
    }
Ejemplo n.º 2
0
    @Override
    public void readFrom(InputStream stream, ORecordVersion version) throws IOException {
      final ODistributedVersion distributedVersion = (ODistributedVersion) version;

      distributedVersion.counter = OBinaryProtocol.bytes2int(stream);
      distributedVersion.timestamp = OBinaryProtocol.bytes2long(stream);
      distributedVersion.macAddress = OBinaryProtocol.bytes2long(stream);
    }
Ejemplo n.º 3
0
    @Override
    public int readFrom(byte[] iStream, int pos, ORecordVersion version) {
      final ODistributedVersion distributedVersion = (ODistributedVersion) version;

      int len = 0;
      distributedVersion.counter = OBinaryProtocol.bytes2int(iStream, pos + len);
      len += OBinaryProtocol.SIZE_INT;
      distributedVersion.timestamp = OBinaryProtocol.bytes2long(iStream, pos + len);
      len += OBinaryProtocol.SIZE_LONG;
      distributedVersion.macAddress = OBinaryProtocol.bytes2long(iStream, pos + len);
      len += OBinaryProtocol.SIZE_LONG;
      return len;
    }
Ejemplo n.º 4
0
    @Override
    public int writeTo(byte[] stream, int pos, ORecordVersion version) {
      final ODistributedVersion distributedVersion = (ODistributedVersion) version;

      int len = 0;
      OBinaryProtocol.int2bytes(distributedVersion.counter, stream, pos + len);
      len += OBinaryProtocol.SIZE_INT;
      OBinaryProtocol.long2bytes(distributedVersion.timestamp, stream, pos + len);
      len += OBinaryProtocol.SIZE_LONG;
      OBinaryProtocol.long2bytes(distributedVersion.macAddress, stream, pos + len);
      len += OBinaryProtocol.SIZE_LONG;

      return len;
    }
Ejemplo n.º 5
0
  public Object fromStream(final byte[] iStream) throws IOException {
    if (iStream == null) return null;

    final String s = OBinaryProtocol.bytes2string(iStream);

    return FORMAT.embeddedCollectionFromStream(null, OType.EMBEDDEDSET, null, OType.LINK, s);
  }
Ejemplo n.º 6
0
  public ORecordId fromStream(final byte[] iBuffer) {
    if (iBuffer != null) {
      clusterId = OBinaryProtocol.bytes2short(iBuffer, 0);

      clusterPosition =
          OClusterPositionFactory.INSTANCE.fromStream(iBuffer, OBinaryProtocol.SIZE_SHORT);
    }
    return this;
  }
Ejemplo n.º 7
0
  @Override
  public OMVRBTreeRIDSet deserialize(byte[] stream, int startPosition) {
    final byte[] serializedSet = OBinaryTypeSerializer.INSTANCE.deserialize(stream, startPosition);

    final String s = OBinaryProtocol.bytes2string(serializedSet);

    return (OMVRBTreeRIDSet)
        FORMAT.embeddedCollectionFromStream(null, OType.EMBEDDEDSET, null, OType.LINK, s);
  }
Ejemplo n.º 8
0
  @Override
  public OMVRBTreeRIDSet deserializeFromDirectMemory(ODirectMemoryPointer pointer, long offset) {
    final byte[] serializedSet =
        OBinaryTypeSerializer.INSTANCE.deserializeFromDirectMemory(pointer, offset);

    final String s = OBinaryProtocol.bytes2string(serializedSet);

    return (OMVRBTreeRIDSet)
        FORMAT.embeddedCollectionFromStream(null, OType.EMBEDDEDSET, null, OType.LINK, s);
  }
Ejemplo n.º 9
0
  public byte[] toStream() {
    final int serializedSize = OClusterPositionFactory.INSTANCE.getSerializedSize();

    byte[] buffer = new byte[OBinaryProtocol.SIZE_SHORT + serializedSize];

    OBinaryProtocol.short2bytes((short) clusterId, buffer, 0);
    System.arraycopy(
        clusterPosition.toStream(), 0, buffer, OBinaryProtocol.SIZE_SHORT, serializedSize);

    return buffer;
  }
  public ORecordInternal<?> fromStream(
      final byte[] iSource, final ORecordInternal<?> iRecord, final String[] iFields) {
    final long timer = PROFILER.startChrono();

    try {
      return fromString(OBinaryProtocol.bytes2string(iSource), iRecord, iFields);
    } finally {

      PROFILER.stopChrono(
          PROFILER.getProcessMetric("serializer.record.string.fromStream"),
          "Deserialize record from stream",
          timer);
    }
  }
Ejemplo n.º 11
0
  public void send(
      final int iCode,
      final String iReason,
      final String iContentType,
      final Object iContent,
      final String iHeaders,
      final boolean iKeepAlive)
      throws IOException {
    if (sendStarted)
      // AVOID TO SEND RESPONSE TWICE
      return;
    sendStarted = true;

    final String content;
    final String contentType;

    if (callbackFunction != null) {
      content = callbackFunction + "(" + iContent + ")";
      contentType = "text/javascript";
    } else {
      content = iContent != null ? iContent.toString() : null;
      contentType = iContentType;
    }

    final boolean empty = content == null || content.length() == 0;

    writeStatus(empty && iCode == 200 ? 204 : iCode, iReason);
    writeHeaders(contentType, iKeepAlive);

    if (additionalHeaders != null) for (String h : additionalHeaders) writeLine(h);

    if (iHeaders != null) writeLine(iHeaders);

    final String sessId = sessionId != null ? sessionId : "-";

    writeLine("Set-Cookie: " + OHttpUtils.OSESSIONID + "=" + sessId + "; Path=/; HttpOnly");

    final byte[] binaryContent = empty ? null : OBinaryProtocol.string2bytes(content);

    writeLine(OHttpUtils.HEADER_CONTENT_LENGTH + (empty ? 0 : binaryContent.length));

    writeLine(null);

    if (binaryContent != null) out.write(binaryContent);
    out.flush();
  }
  public byte[] toStream(final ORecordInternal<?> iRecord, boolean iOnlyDelta) {
    final long timer = PROFILER.startChrono();

    try {
      return OBinaryProtocol.string2bytes(
          toString(
                  iRecord,
                  new StringBuilder(),
                  null,
                  null,
                  OSerializationLongIdThreadLocal.INSTANCE.get(),
                  iOnlyDelta,
                  true)
              .toString());
    } finally {

      PROFILER.stopChrono(
          PROFILER.getProcessMetric("serializer.record.string.toStream"),
          "Serialize record to stream",
          timer);
    }
  }
Ejemplo n.º 13
0
 public int toStream(final OMemoryStream iStream) throws IOException {
   final int beginOffset = OBinaryProtocol.short2bytes((short) clusterId, iStream);
   iStream.write(clusterPosition.toStream());
   return beginOffset;
 }
Ejemplo n.º 14
0
  public ORecordId fromStream(final InputStream iStream) throws IOException {
    clusterId = OBinaryProtocol.bytes2short(iStream);

    clusterPosition = OClusterPositionFactory.INSTANCE.fromStream(iStream);
    return this;
  }
Ejemplo n.º 15
0
 public void writeContent(final String iContent) throws IOException {
   if (iContent != null) out.write(OBinaryProtocol.string2bytes(iContent));
 }