本文整理了Java中com.esotericsoftware.kryo.io.Output.setPosition()
方法的一些代码示例,展示了Output.setPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Output.setPosition()
方法的具体详情如下:
包路径:com.esotericsoftware.kryo.io.Output
类名称:Output
方法名:setPosition
[英]Sets the current position in the buffer.
[中]设置缓冲区中的当前位置。
代码示例来源:origin: com.vmware.dcp/dcp-common
public static int toBytes(Object o, byte[] buffer, int position) {
Kryo k = kryoForObjectPerThread.get();
Output out = new Output(buffer);
out.setPosition(position);
k.writeClassAndObject(out, o);
return out.position();
}
代码示例来源:origin: com.vmware.dcp/dcp-common
public static int toBytes(ServiceDocument o, byte[] buffer, int position) {
Kryo k = kryoForDocumentPerThread.get();
Output out = new Output(buffer);
out.setPosition(position);
k.writeClassAndObject(out, o);
return out.position();
}
代码示例来源:origin: vmware/xenon
/**
* Serializes an arbitrary object into a binary representation, using full
* reference tracking and the object graph serializer.
* Must be paired with {@code KryoSerializers#fromBytes(byte[], int, int)} or
* {@code KryoSerializers#fromBytes(byte[])}
*/
public static int serializeObject(Object o, byte[] buffer, int position) {
Kryo k = getKryoThreadLocalForObjects();
Output out = new Output(buffer, buffer.length);
out.setPosition(position);
k.writeClassAndObject(out, o);
return out.position();
}
代码示例来源:origin: co.paralleluniverse/quasar-core
@Override
public void write(Kryo kryo, Output output, ThreadLocal<?> tl) {
output.writeBoolean(tl instanceof InheritableThreadLocal);
final Object val = tl.get();
final int pos = output.position();
try {
kryo.writeClassAndObject(output, val);
} catch (RuntimeException e) {
if (PRINT_WARNINGS_ON_UNSERIALIZABLE_THREAD_LOCAL)
System.err.println("WARNING: Cannot serialize ThreadLocal (" + tl + " = " + val + "), it will be restored as null.");
output.setPosition(pos);
kryo.writeObject(output, new DEFAULT());
}
}
代码示例来源:origin: org.apache.apex/apex-engine
@Override
public DataStatePair toDataStatePair(T o)
{
data.setPosition(0);
writeClassAndObject(data, o);
if (!pairs.isEmpty()) {
state.setPosition(0);
for (ClassIdPair cip : pairs) {
writeClassAndObject(state, cip);
}
pairs.clear();
dataStatePair.state = new Slice(state.getBuffer(), 0, state.position());
} else {
dataStatePair.state = null;
}
dataStatePair.data = new Slice(data.getBuffer(), 0, data.position());
return dataStatePair;
}
代码示例来源:origin: us.ihmc/IHMCCommunication
/**
* Blocking write to an outputStream
*
* @param outputStream output stream to write to
* @param object object to write
*
* @return Number of bytes written
*
* @throws IOException
*/
public int write(OutputStream outputStream, Object object) throws IOException
{
output.clear();
output.setPosition(4);
kryo.writeClassAndObject(output, object);
int length = output.position() - 4;
writeIntToWriteBuffer(length);
outputStream.write(writeBuffer, 0, output.position());
return length + 4;
}
代码示例来源:origin: net.dempsy/dempsy-serialization.kryo
@Override
public <T> void serialize(final T object, final MessageBufferOutput buffer) throws IOException {
try (Holder k = getKryoHolder()) {
final Output output = k.output;
// this will allow kryo to grow the buffer as needed.
output.setBuffer(buffer.getBuffer(), Integer.MAX_VALUE);
output.setPosition(buffer.getPosition()); // set the position to where we already are.
kryoRunner.doSerialize(k, output, object);
// if we resized then we need to adjust the message buffer
if (output.getBuffer() != buffer.getBuffer())
buffer.replace(output.getBuffer());
buffer.setPosition(output.position());
} catch (final KryoException ke) {
throw new IOException("Failed to serialize.", ke);
} catch (final IllegalArgumentException e) { // this happens when requiring registration but serializing an unregistered class
throw new IOException("Failed to serialize " + objectDescription(object) +
" (did you require registration and attempt to serialize an unregistered class?)", e);
}
}
内容来源于网络,如有侵权,请联系作者删除!