org.apache.tinkerpop.shaded.kryo.io.Output.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中org.apache.tinkerpop.shaded.kryo.io.Output.<init>()方法的一些代码示例,展示了Output.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Output.<init>()方法的具体详情如下:
包路径:org.apache.tinkerpop.shaded.kryo.io.Output
类名称:Output
方法名:<init>

Output.<init>介绍

暂无

代码示例

代码示例来源:origin: apache/tinkerpop

public GryoSerializationStream(final GryoSerializerInstance gryoSerializer, final OutputStream outputStream) {
  this.output = new Output(outputStream);
  this.gryoSerializer = gryoSerializer;
}

代码示例来源:origin: apache/tinkerpop

public Output newOutput() {
  return new Output(this.bufferSize, this.maxBufferSize);
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeObject(final OutputStream outputStream, final Object object) {
  final Output output = new Output(outputStream);
  this.kryo.writeClassAndObject(output, object);
  output.flush();
}

代码示例来源:origin: hugegraph/hugegraph

public static byte[] toKryo(Object value) {
  try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
     Output output = new Output(bos, 256)) {
    kryo().writeObject(output, value);
    output.flush();
    return bos.toByteArray();
  } catch (IOException e) {
    throw new BackendException("Failed to serialize: %s", e, value);
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public ByteBuf serializeRequestAsBinary(final RequestMessage requestMessage, final ByteBufAllocator allocator) throws SerializationException {
  ByteBuf encodedMessage = null;
  try {
    final Kryo kryo = kryoThreadLocal.get();
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      final Output output = new Output(baos, bufferSize);
      final String mimeType = mimeTypesSupported()[0];
      output.writeByte(mimeType.length());
      output.write(mimeType.getBytes(UTF8));
      kryo.writeObject(output, requestMessage);
      final long size = output.total();
      if (size > Integer.MAX_VALUE)
        throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
      output.flush();
      encodedMessage = allocator.buffer((int) size);
      encodedMessage.writeBytes(baos.toByteArray());
    }
    return encodedMessage;
  } catch (Exception ex) {
    if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
    logger.warn(String.format("Request [%s] could not be serialized by %s.", requestMessage, AbstractGryoMessageSerializerV3d0.class.getName()), ex);
    throw new SerializationException(ex);
  }
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeVertexProperty(final OutputStream outputStream, final VertexProperty vp) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(vp, true));
  output.flush();
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeProperty(final OutputStream outputStream, final Property p) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(p, true));
  output.flush();
}

代码示例来源:origin: apache/tinkerpop

@Override
public void writeClassAndObject(final Object object, final OutputStream outputStream) {
  HadoopPools.getGryoPool().writeWithKryo(kryo -> {
    final Output output = new Output(outputStream);
    kryo.writeClassAndObject(output, object);
    output.flush();
  });
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeEdge(final OutputStream outputStream, final Edge e) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(e, true));
  output.flush();
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeVertices(final OutputStream outputStream, final Iterator<Vertex> vertexIterator, final Direction direction) throws IOException {
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(direction));
  final Output output = new Output(outputStream);
  while (vertexIterator.hasNext()) {
    writeVertexInternal(output, vertexIterator.next());
  }
  output.flush();
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(Direction.BOTH));
}

代码示例来源:origin: apache/tinkerpop

@Override
public ByteBuf serializeRequestAsBinary(final RequestMessage requestMessage, final ByteBufAllocator allocator) throws SerializationException {
  ByteBuf encodedMessage = null;
  try {
    final Kryo kryo = kryoThreadLocal.get();
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      final Output output = new Output(baos, bufferSize);
      final String mimeType = mimeTypesSupported()[0];
      output.writeByte(mimeType.length());
      output.write(mimeType.getBytes(UTF8));
      kryo.writeObject(output, requestMessage.getRequestId());
      output.writeString(requestMessage.getProcessor());
      output.writeString(requestMessage.getOp());
      kryo.writeObject(output, requestMessage.getArgs());
      final long size = output.total();
      if (size > Integer.MAX_VALUE)
        throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
      output.flush();
      encodedMessage = allocator.buffer((int) size);
      encodedMessage.writeBytes(baos.toByteArray());
    }
    return encodedMessage;
  } catch (Exception ex) {
    if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
    logger.warn(String.format("Request [%s] could not be serialized by %s.", requestMessage, AbstractGryoMessageSerializerV1d0.class.getName()), ex);
    throw new SerializationException(ex);
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException {
  ByteBuf encodedMessage = null;
  try {
    final Kryo kryo = kryoThreadLocal.get();
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      final Output output = new Output(baos, bufferSize);
      // request id - if present
      kryo.writeObjectOrNull(output, responseMessage.getRequestId() != null ? responseMessage.getRequestId() : null, UUID.class);
      // status
      output.writeShort(responseMessage.getStatus().getCode().getValue());
      output.writeString(responseMessage.getStatus().getMessage());
      kryo.writeClassAndObject(output, responseMessage.getStatus().getAttributes());
      // result
      kryo.writeClassAndObject(output, serializeToString ? serializeResultToString(responseMessage) : responseMessage.getResult().getData());
      kryo.writeClassAndObject(output, responseMessage.getResult().getMeta());
      final long size = output.total();
      if (size > Integer.MAX_VALUE)
        throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
      output.flush();
      encodedMessage = allocator.buffer((int) size);
      encodedMessage.writeBytes(baos.toByteArray());
    }
    return encodedMessage;
  } catch (Exception ex) {
    if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
    logger.warn(String.format("Response [%s] could not be serialized by %s.", responseMessage, AbstractGryoMessageSerializerV1d0.class.getName()), ex);
    throw new SerializationException(ex);
  }
}

代码示例来源:origin: apache/tinkerpop

@Override
public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException {
  ByteBuf encodedMessage = null;
  try {
    final Kryo kryo = kryoThreadLocal.get();
    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
      final Output output = new Output(baos, bufferSize);
      final ResponseMessage msgToWrite = !serializeToString ? responseMessage :
          ResponseMessage.build(responseMessage.getRequestId())
            .code(responseMessage.getStatus().getCode())
            .statusAttributes(responseMessage.getStatus().getAttributes())
            .responseMetaData(responseMessage.getResult().getMeta())
            .result(serializeResultToString(responseMessage))
            .statusMessage(responseMessage.getStatus().getMessage()).create();
      kryo.writeObject(output, msgToWrite);
      final long size = output.total();
      if (size > Integer.MAX_VALUE)
        throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size));
      output.flush();
      encodedMessage = allocator.buffer((int) size);
      encodedMessage.writeBytes(baos.toByteArray());
    }
    return encodedMessage;
  } catch (Exception ex) {
    if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage);
    logger.warn(String.format("Response [%s] could not be serialized by %s.", responseMessage, AbstractGryoMessageSerializerV3d0.class.getName()), ex);
    throw new SerializationException(ex);
  }
}

代码示例来源:origin: apache/tinkerpop

/**
 * {@inheritDoc}
 */
@Override
public void writeVertex(final OutputStream outputStream, final Vertex v, final Direction direction) throws IOException {
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(direction));
  final Output output = new Output(outputStream);
  writeVertexInternal(output, v);
  output.flush();
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(Direction.BOTH));
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

/**
 * {@inheritDoc}
 */
@Override
public void writeObject(final OutputStream outputStream, final Object object) {
  final Output output = new Output(outputStream);
  this.kryo.writeClassAndObject(output, object);
  output.flush();
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

/**
 * {@inheritDoc}
 */
@Override
public void writeProperty(final OutputStream outputStream, final Property p) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(p, true));
  output.flush();
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

/**
 * {@inheritDoc}
 */
@Override
public void writeEdge(final OutputStream outputStream, final Edge e) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(e, true));
  output.flush();
}

代码示例来源:origin: org.apache.tinkerpop/hadoop-gremlin

@Override
public void writeClassAndObject(final Object object, final OutputStream outputStream) {
  HadoopPools.getGryoPool().writeWithKryo(kryo -> {
    final Output output = new Output(outputStream);
    kryo.writeClassAndObject(output, object);
    output.flush();
  });
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

/**
 * {@inheritDoc}
 */
@Override
public void writeVertexProperty(final OutputStream outputStream, final VertexProperty vp) throws IOException {
  final Output output = new Output(outputStream);
  writeHeader(output);
  kryo.writeObject(output, DetachedFactory.detach(vp, true));
  output.flush();
}

代码示例来源:origin: org.apache.tinkerpop/gremlin-core

/**
 * {@inheritDoc}
 */
@Override
public void writeVertex(final OutputStream outputStream, final Vertex v, final Direction direction) throws IOException {
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(direction));
  final Output output = new Output(outputStream);
  writeVertexInternal(output, v);
  output.flush();
  kryo.getRegistration(StarGraph.class).setSerializer(StarGraphGryoSerializer.with(Direction.BOTH));
}

相关文章