本文整理了Java中org.apache.tinkerpop.shaded.kryo.Kryo.writeObject()
方法的一些代码示例,展示了Kryo.writeObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Kryo.writeObject()
方法的具体详情如下:
包路径:org.apache.tinkerpop.shaded.kryo.Kryo
类名称:Kryo
方法名:writeObject
暂无
代码示例来源:origin: hugegraph/hugegraph
@Override
public void write(Kryo kryo, Output output, Optional<?> optional) {
if (optional.isPresent()) {
kryo.writeClassAndObject(output, optional.get());
} else {
kryo.writeObject(output, null);
}
}
代码示例来源:origin: apache/tinkerpop
@Override
public void writeObject(final ShadedOutputAdapter output, final Object object) {
shadedKryo.writeObject(output.getShadedOutput(), object);
}
代码示例来源:origin: hugegraph/hugegraph
private static void writeEntry(Kryo kryo,
Output output,
Map<HugeKeys, Object> schema) {
/* Write columns size and data */
output.writeInt(schema.keySet().size());
for (Map.Entry<HugeKeys, Object> entry : schema.entrySet()) {
kryo.writeObject(output, entry.getKey());
kryo.writeClassAndObject(output, entry.getValue());
}
}
代码示例来源: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
void writeVertexInternal(final Output output, final Vertex v) throws IOException {
writeHeader(output);
kryo.writeObject(output, StarGraph.of(v));
kryo.writeClassAndObject(output, VertexTerminator.INSTANCE);
}
代码示例来源: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 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
/**
* {@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 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
@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);
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: org.apache.tinkerpop/gremlin-core
@Override
public void writeObject(final ShadedOutputAdapter output, final Object object) {
shadedKryo.writeObject(output.getShadedOutput(), object);
}
代码示例来源:origin: com.baidu.hugegraph/hugegraph-core
@Override
public void write(Kryo kryo, Output output, Optional<?> optional) {
if (optional.isPresent()) {
kryo.writeClassAndObject(output, optional.get());
} else {
kryo.writeObject(output, null);
}
}
代码示例来源:origin: com.baidu.hugegraph/hugegraph-core
private static void writeEntry(Kryo kryo,
Output output,
Map<HugeKeys, Object> schema) {
/* Write columns size and data */
output.writeInt(schema.keySet().size());
for (Map.Entry<HugeKeys, Object> entry : schema.entrySet()) {
kryo.writeObject(output, entry.getKey());
kryo.writeClassAndObject(output, entry.getValue());
}
}
代码示例来源:origin: com.baidu.hugegraph/hugegraph-core
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: org.apache.tinkerpop/gremlin-core
void writeVertexInternal(final Output output, final Vertex v) throws IOException {
writeHeader(output);
kryo.writeObject(output, StarGraph.of(v));
kryo.writeClassAndObject(output, VertexTerminator.INSTANCE);
}
代码示例来源:origin: org.apache.tinkerpop/gremlin-driver
@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: 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/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();
}
内容来源于网络,如有侵权,请联系作者删除!