本文整理汇总了Java中com.esotericsoftware.kryo.io.ByteBufferOutput类的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferOutput类的具体用法?Java ByteBufferOutput怎么用?Java ByteBufferOutput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteBufferOutput类属于com.esotericsoftware.kryo.io包,在下文中一共展示了ByteBufferOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
/**
* Serializes given object to byte array using Kryo instance in pool.
*
* @param obj Object to serialize
* @param bufferSize maximum size of serialized bytes
* @return serialized bytes
*/
public byte[] serialize(final Object obj, final int bufferSize) {
ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
try {
Kryo kryo = borrow();
try {
kryo.writeClassAndObject(out, obj);
out.flush();
return out.toBytes();
} finally {
release(kryo);
}
} finally {
out.release();
}
}
示例2: testSerialization
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Test
public void testSerialization() throws Exception {
User user = new User(1, "admin", new Date());
Kryo kryo = new Kryo();
ByteBufferOutput output = new ByteBufferOutput(10240);
kryo.writeObject(output, user);
byte[] bytes = output.toBytes();
System.out.println("Saved bytes: " + Bytes.toString(bytes));
ssdbClient.set("kryo_user", bytes);
//////////////////////////////////////////////////////////////
byte[] readBytes = ssdbClient.getBytes("kryo_user");
System.out.println("Read bytes: " + Bytes.toString(readBytes));
Assert.assertEquals(bytes.length, readBytes.length);
}
示例3: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override
public byte[] serialize(String topic, Measurement record) {
int byteBufferLength = 50;
if (record instanceof HSMMeasurement) {
byteBufferLength = 7600 * 2 * 100; // TODO: improve
}
ByteBufferOutput output = new ByteBufferOutput(byteBufferLength);
kryos.get().writeObject(output, record);
return output.toBytes();
}
示例4: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
/**
* Serializes given object to byte array using Kryo instance in pool.
*
* @param obj Object to serialize
* @param bufferSize maximum size of serialized bytes
* @return serialized bytes
*/
public byte[] serialize(final Object obj, final int bufferSize) {
ByteBufferOutput out = new ByteBufferOutput(bufferSize, MAX_BUFFER_SIZE);
Kryo kryo = borrow();
try {
kryo.writeClassAndObject(out, obj);
out.flush();
return out.toBytes();
} finally {
release(kryo);
}
}
示例5: KryoSerialization
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
public KryoSerialization (Kryo kryo) {
this.kryo = kryo;
kryo.register(RegisterTCP.class);
kryo.register(RegisterUDP.class);
kryo.register(KeepAlive.class);
kryo.register(DiscoverHost.class);
kryo.register(Ping.class);
input = new ByteBufferInput();
output = new ByteBufferOutput();
}
示例6: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
/**
* Serializes given object to byte buffer using Kryo instance in pool.
*
* @param obj Object to serialize
* @param buffer to write to
*/
public void serialize(final Object obj, final ByteBuffer buffer) {
ByteBufferOutput out = new ByteBufferOutput(buffer);
Kryo kryo = borrow();
try {
kryo.writeClassAndObject(out, obj);
out.flush();
} finally {
release(kryo);
}
}
示例7: run
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override
public void run() {
Kryo kryoInstance = kryoPool.getKryo();
KafkaProducerPool pool = KafkaProducerPool.getInstance();
KafkaProducer producer = pool.getProducer();
try {
for (WebTxnData dataItem : dataBatch) {
ByteBufferOutput bufferOutput = new ByteBufferOutput(4096);
kryoInstance.writeObject(bufferOutput, dataItem);
byte[] msgBytes = bufferOutput.toBytes();
bufferOutput.clear();
//serialize item
byte[] keyBytes = UUID.randomUUID().toString().getBytes();
KeyedMessage<byte[], byte[]> message = new KeyedMessage<byte[], byte[]>(MsgConstants.WEB_TXN_TOPIC_NAME,
keyBytes,
msgBytes);
// message producer is Async , it will queue and send out the pipe
//order doesn't matter
producer.sendMsg(message);
}
dataBatch.clear();
} catch (Exception e) {
logger.warn("Exception in sending message");
} finally {
pool.returnToPool(producer);
kryoPool.returnToPool(kryoInstance);
}
}
示例8: run
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override
public void run() {
Kryo kryoInstance = kryoPool.getKryo();
KafkaProducerPool pool = KafkaProducerPool.getInstance();
KafkaProducer producer = pool.getProducer();
try {
for (WebTxnData dataItem : dataBatch) {
ByteBufferOutput bufferOutput = new ByteBufferOutput(4096);
kryoInstance.writeObject(bufferOutput, dataItem);
byte[] msgBytes = bufferOutput.toBytes();
bufferOutput.clear();
//serialize item
byte[] keyBytes = String.valueOf(random.nextInt()).getBytes();
KeyedMessage<byte[], byte[]> message = new KeyedMessage<byte[], byte[]>(MsgConstants.WEB_TXN_TOPIC_NAME,
keyBytes,
msgBytes);
// message producer is Async , it will queue and send out the pipe
//order doesn't matter
producer.sendMsg(message);
}
dataBatch.clear();
} catch (Exception e) {
logger.warn("Exception in sending message");
} finally {
pool.returnToPool(producer);
kryoPool.returnToPool(kryoInstance);
}
}
示例9: toBytes
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override
public byte[] toBytes(Object dataItem) {
Kryo kryoInstance = pool.getKryo();
ByteBufferOutput bufferOutput = new ByteBufferOutput(4096);
kryoInstance.writeObject(bufferOutput,dataItem);
byte [] msg = bufferOutput.toBytes();
bufferOutput.clear();
pool.returnToPool(kryoInstance);
return msg;
}
示例10: KryoSerialization
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
public KryoSerialization(Kryo kryo) {
this.kryo = kryo;
kryo.register(RegisterTCP.class);
kryo.register(RegisterUDP.class);
kryo.register(KeepAlive.class);
kryo.register(DiscoverHost.class);
kryo.register(Ping.class);
input = new ByteBufferInput();
output = new ByteBufferOutput();
}
示例11: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
/**
* Serializes given object to byte buffer using Kryo instance in pool.
*
* @param obj Object to serialize
* @param buffer to write to
*/
public void serialize(final Object obj, final ByteBuffer buffer) {
ByteBufferOutput out = new ByteBufferOutput(buffer);
Kryo kryo = borrow();
try {
kryo.writeClassAndObject(out, obj);
out.flush();
} finally {
release(kryo);
}
}
示例12: serialize
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override
public byte[] serialize(String s, SensorReading sensorReading) {
ByteBufferOutput output = new ByteBufferOutput(100);
kryos.get().writeObject(output, sensorReading);
return output.toBytes();
}
示例13: main
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
public static void main(String [] args){
String str = "India,Search,Asia";
System.out.println("string is " + str.getBytes());
Kryo kryo =KryoPool.getInstance().getKryo();
ByteBufferOutput bufferOutput = new ByteBufferOutput(20);
kryo.writeObject(bufferOutput, str);
byte[] msgBytes = bufferOutput.toBytes();
System.out.println(msgBytes.length);
ByteBufferInput input = new ByteBufferInput(msgBytes.length);
input.setBuffer(msgBytes);
String str2 = kryo.readObject(input,String.class);
System.out.println(str2);
KryoPool.getInstance().returnToPool(kryo);
}
示例14: initialValue
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
protected Output initialValue() {
return new ByteBufferOutput(EXPECTED_BUFFER_SIZE, MAX_BUFFER_SIZE);
}
示例15: initialValue
import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override protected ByteBufferOutput initialValue() {
return new ByteBufferOutput(10240);
}