当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufferOutput类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:KryoNamespace.java

示例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);
}
 
开发者ID:yiding-he,项目名称:hydrogen-ssdb,代码行数:19,代码来源:KryoSerializationTest.java

示例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();
}
 
开发者ID:proteus-h2020,项目名称:proteus-consumer-couchbase,代码行数:11,代码来源:ProteusSerializer.java

示例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);
    }
}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:19,代码来源:KryoNamespace.java

示例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();
}
 
开发者ID:abejfehr,项目名称:magic-realm,代码行数:13,代码来源:KryoSerialization.java

示例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);
  }
}
 
开发者ID:atomix,项目名称:atomix,代码行数:17,代码来源:KryoNamespace.java

示例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);
    }
}
 
开发者ID:sumanthn,项目名称:dataflux,代码行数:37,代码来源:WebTxnKafkaProducer.java

示例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);
    }
}
 
开发者ID:sumanthn,项目名称:dataflux,代码行数:37,代码来源:WebTxnFeeder.java

示例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;
}
 
开发者ID:sumanthn,项目名称:dataflux,代码行数:12,代码来源:WebTxnSerializer.java

示例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();
}
 
开发者ID:MosaicOwl,项目名称:the-erder,代码行数:13,代码来源:KryoSerialization.java

示例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);
    }
}
 
开发者ID:opennetworkinglab,项目名称:onos,代码行数:17,代码来源:KryoNamespace.java

示例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();
}
 
开发者ID:nielsutrecht,项目名称:kafka-serializer-example,代码行数:7,代码来源:KryoReadingSerializer.java

示例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);


}
 
开发者ID:sumanthn,项目名称:hashaggregator,代码行数:22,代码来源:GenericGroupByKeyTest.java

示例14: initialValue

import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
protected Output initialValue() {
    return new ByteBufferOutput(EXPECTED_BUFFER_SIZE, MAX_BUFFER_SIZE);
}
 
开发者ID:SyncFree,项目名称:SwiftCloud,代码行数:4,代码来源:MetadataStatsCollector.java

示例15: initialValue

import com.esotericsoftware.kryo.io.ByteBufferOutput; //导入依赖的package包/类
@Override protected ByteBufferOutput initialValue() {
    return new ByteBufferOutput(10240);
}
 
开发者ID:lyogavin,项目名称:Pistachio,代码行数:4,代码来源:KeyValueEncoder.java


注:本文中的com.esotericsoftware.kryo.io.ByteBufferOutput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。