本文整理了Java中com.esotericsoftware.kryo.io.Output.getBuffer()
方法的一些代码示例,展示了Output.getBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Output.getBuffer()
方法的具体详情如下:
包路径:com.esotericsoftware.kryo.io.Output
类名称:Output
方法名:getBuffer
[英]Returns the buffer. The bytes between zero and #position() are the data that has been written.
[中]返回缓冲区。零和#position()之间的字节是已写入的数据。
代码示例来源:origin: apache/storm
/**
* Serializes the given object into a {@link ByteBuffer} backed by the byte array returned by Kryo serialization.
*
* @param obj Object to be serialized.
*/
public ByteBuffer serializeToByteBuffer(Object obj) {
output.clear();
kryo.writeClassAndObject(output, obj);
return ByteBuffer.wrap(output.getBuffer(), 0, output.position());
}
代码示例来源:origin: fengjiachun/Jupiter
public static void clearOutput(Output output) {
output.clear();
// 防止hold过大的内存块一直不释放
byte[] bytes = output.getBuffer();
if (bytes == null) {
return;
}
if (bytes.length > MAX_CACHED_BUF_SIZE) {
output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1);
}
}
代码示例来源:origin: fengjiachun/Jupiter
public static void clearOutput(Output output) {
output.clear();
// 防止hold过大的内存块一直不释放
byte[] bytes = output.getBuffer();
if (bytes == null) {
return;
}
if (bytes.length > MAX_CACHED_BUF_SIZE) {
output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1);
}
}
代码示例来源:origin: apache/kylin
public static byte[] serialize(final Kryo kryo, final Object o) {
if (o == null) {
throw new NullPointerException("Can't serialize null");
}
final Output output = new Output(4096);
kryo.writeObject(output, o);
output.flush();
return output.getBuffer();
}
代码示例来源:origin: apache/storm
/**
* Reads a string encrypted by another instance with a shared key
*/
private void testEncryptsAndDecryptsMessage(Map<String, Object> topoConf) {
String testText = "Tetraodontidae is a family of primarily marine and estuarine fish of the order" +
" Tetraodontiformes. The family includes many familiar species, which are" +
" variously called pufferfish, puffers, balloonfish, blowfish, bubblefish," +
" globefish, swellfish, toadfish, toadies, honey toads, sugar toads, and sea" +
" squab.[1] They are morphologically similar to the closely related" +
" porcupinefish, which have large external spines (unlike the thinner, hidden" +
" spines of Tetraodontidae, which are only visible when the fish has puffed up)." +
" The scientific name refers to the four large teeth, fused into an upper and" +
" lower plate, which are used for crushing the shells of crustaceans and" +
" mollusks, their natural prey.";
Kryo kryo = new Kryo();
BlowfishTupleSerializer writerBTS = new BlowfishTupleSerializer(kryo, topoConf);
BlowfishTupleSerializer readerBTS = new BlowfishTupleSerializer(kryo, topoConf);
int bufferSize = 1024;
Output output = new Output(bufferSize, bufferSize);
Input input = new Input(bufferSize);
String[] stringList = testText.split(" ");
ListDelegate delegate = new ListDelegate();
delegate.addAll(Arrays.asList(stringList));
writerBTS.write(kryo, output, delegate);
input.setBuffer(output.getBuffer());
ListDelegate outDelegate = readerBTS.read(kryo, input, ListDelegate.class);
Assert.assertEquals(testText, Joiner.on(" ").join(outDelegate.toArray()));
}
}
代码示例来源:origin: net.spals.appbuilder/spals-appbuilder-model-core
@Override
public byte[] serialize(final Object modelObject) {
try (final Output kryoOutput = new Output(32 /*bufferSize*/, -1 /*maxBufferSize*/)) {
kryo.writeClassAndObject(kryoOutput, modelObject);
return kryoOutput.getBuffer();
}
}
}
代码示例来源:origin: net.spals.appbuilder.plugins/spals-appbuilder-model-protobuf
@Override
public byte[] serialize(final Object modelObject) {
Preconditions.checkArgument(modelObject instanceof MessageLite || modelObject instanceof GeneratedMessage,
"Cannot serialize non Protobuf object %s", modelObject.getClass());
try (final Output kryoOutput = new Output(32 /*bufferSize*/, -1 /*maxBufferSize*/)) {
kryo.writeClassAndObject(kryoOutput, modelObject);
return kryoOutput.getBuffer();
}
}
}
代码示例来源:origin: org.apache.rya/rya.pcj.fluo.app
/**
* Serializes RyaSubGraph to bytes
* @param bundle - RyaSubGraph to be serialized
* @return - serialized bytes from RyaSubGraph
*/
public byte[] toBytes(RyaSubGraph bundle) {
Output output = new Output(new ByteArrayOutputStream());
kryo.writeObject(output, bundle, new RyaSubGraphSerializer());
return output.getBuffer();
}
代码示例来源:origin: apache/incubator-rya
/**
* Serializes RyaSubGraph to bytes
* @param bundle - RyaSubGraph to be serialized
* @return - serialized bytes from RyaSubGraph
*/
public byte[] toBytes(RyaSubGraph bundle) {
Output output = new Output(new ByteArrayOutputStream());
kryo.writeObject(output, bundle, new RyaSubGraphSerializer());
return output.getBuffer();
}
代码示例来源:origin: usdot-jpo-ode/jpo-ode
public byte[] serialize(T object) {
if (object == null) {
return null;
}
Output output = new Output(1024, -1);
kryo.writeClassAndObject(output, object);
byte[] bytes = output.getBuffer();
output.close();
return bytes;
}
代码示例来源:origin: vmware/xenon
/**
* @see #serializeObject(Object, byte[], int)
*/
public static ByteBuffer serializeObject(Object o, int maxSize) {
Kryo k = getKryoThreadLocalForObjects();
Output out = new Output(DEFAULT_BUFFER_SIZE_BYTES, maxSize);
k.writeClassAndObject(out, o);
return ByteBuffer.wrap(out.getBuffer(), 0, out.position());
}
代码示例来源:origin: org.hawkular.titan/titan-core
private void writeOutput(WriteBuffer out, Output output) {
byte[] array = output.getBuffer();
int limit = output.position();
for (int i=0;i<limit;i++) out.putByte(array[i]);
}
代码示例来源:origin: org.jupiter-rpc/jupiter-serialization-kryo
public static void clearOutput(Output output) {
output.clear();
// 防止hold过大的内存块一直不释放
byte[] bytes = output.getBuffer();
if (bytes == null) {
return;
}
if (bytes.length > MAX_CACHED_BUF_SIZE) {
output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1);
}
}
代码示例来源:origin: org.jupiter-rpc/jupiter-all
public static void clearOutput(Output output) {
output.clear();
// 防止hold过大的内存块一直不释放
byte[] bytes = output.getBuffer();
if (bytes == null) {
return;
}
if (bytes.length > MAX_CACHED_BUF_SIZE) {
output.setBuffer(new byte[DEFAULT_BUF_SIZE], -1);
}
}
代码示例来源:origin: techery/snapper
@Override
public byte[] toBytes(T item) {
kryo.writeObject(output, item);
output.clear();
return output.getBuffer();
}
代码示例来源:origin: org.apache.storm/storm-core
/**
* Serializes the given object into a {@link ByteBuffer} backed by the byte array returned by Kryo serialization.
*
* @param obj Object to be serialized.
*/
public ByteBuffer serializeToByteBuffer(Object obj) {
output.clear();
kryo.writeClassAndObject(output, obj);
return ByteBuffer.wrap(output.getBuffer(), 0, output.position());
}
代码示例来源:origin: org.apache.apex/apex-engine
@Override
public Slice toByteArray(T o)
{
final Output output = new Output(32, -1);
try {
kryo.writeClassAndObject(output, o);
} finally {
output.close();
}
return new Slice(output.getBuffer(), 0, output.position());
}
代码示例来源:origin: seznam/euphoria
@Test
public void test() {
final Kryo kryo = new Kryo();
kryo.register(TestSingleton.class, SingletonSerializer.of("getInstance"));
final Output output = new Output(1024);
kryo.writeClassAndObject(output, TestSingleton.getInstance());
final Input input = new Input(output.getBuffer());
final TestSingleton deserialized = (TestSingleton) kryo.readClassAndObject(input);
assertEquals(TestSingleton.getInstance(), deserialized);
}
代码示例来源:origin: vmware/xenon
@Test
public void serializeDocumentForIndexing() {
ExampleServiceState state = new ExampleServiceState();
state.documentSelfLink = "selfLink";
state.documentKind = Utils.buildKind(ExampleServiceState.class);
Output o = KryoSerializers.serializeDocumentForIndexing(state, 2048);
ExampleServiceState deser = (ExampleServiceState) KryoSerializers.deserializeDocument(
o.getBuffer(), 0,
o.position());
assertNull(deser.documentSelfLink);
assertNull(deser.documentKind);
}
代码示例来源:origin: com.vmware.xenon/xenon-common
@Test
public void serializeDocumentForIndexing() {
ExampleServiceState state = new ExampleServiceState();
state.documentSelfLink = "selfLink";
state.documentKind = Utils.buildKind(ExampleServiceState.class);
Output o = KryoSerializers.serializeDocumentForIndexing(state, 2048);
ExampleServiceState deser = (ExampleServiceState) KryoSerializers.deserializeDocument(
o.getBuffer(), 0,
o.position());
assertNull(deser.documentSelfLink);
assertNull(deser.documentKind);
}
内容来源于网络,如有侵权,请联系作者删除!