本文整理汇总了Java中com.esotericsoftware.kryo.io.ByteBufferInput类的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferInput类的具体用法?Java ByteBufferInput怎么用?Java ByteBufferInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteBufferInput类属于com.esotericsoftware.kryo.io包,在下文中一共展示了ByteBufferInput类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserialize
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
@Override
public Measurement deserialize(String topic, byte[] bytes) {
// System.out.println("topic" + topic);
// System.out.println("bytes" + bytes);
// System.out.println("bytes" + bytes.length);
// System.out.println("bytse: " + Arrays.toString(bytes));
// System.out.println("kryos: " + kryos.get());
// if ((topic.equals("proteus-realtime") ||
// (topic.equals("proteus-flatness")) && bytes.length > 40)) {
// System.out.println("Escape");
// return null;
// }
if (topic.equals(ProteusData.get("kafka.topicName")) && bytes.length < 40) {
return kryos.get().readObject(new ByteBufferInput(bytes), SensorMeasurement.class);
} else if (topic.equals(ProteusData.get("kafka.flatnessTopicName")) && bytes.length < 40) {
return kryos.get().readObject(new ByteBufferInput(bytes), SensorMeasurement.class);
} else if (topic.equals(ProteusData.get("kafka.hsmTopicName"))) {
return kryos.get().readObject(new ByteBufferInput(bytes), HSMMeasurement.class);
} else {
throw new IllegalArgumentException("Illegal argument: " + topic);
}
}
示例2: deserialize
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
/**
* Deserializes given byte buffer to Object using Kryo instance in pool.
*
* @param buffer input with serialized bytes
* @param <T> deserialized Object type
* @return deserialized Object
*/
public <T> T deserialize(final ByteBuffer buffer) {
ByteBufferInput in = new ByteBufferInput(buffer);
Kryo kryo = borrow();
try {
@SuppressWarnings("unchecked")
T obj = (T) kryo.readClassAndObject(in);
return obj;
} finally {
release(kryo);
}
}
示例3: deserialize
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
@Override
public SensorReading deserialize(String s, byte[] bytes) {
try {
return kryos.get().readObject(new ByteBufferInput(bytes), SensorReading.class);
}
catch(Exception e) {
throw new IllegalArgumentException("Error reading bytes",e);
}
}
示例4: getStringFromBytes
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
public static String getStringFromBytes(final byte [] bytes){
Kryo kryo = KryoPool.getInstance().getKryo();
ByteBufferInput in = new ByteBufferInput(bytes.length+5);
in.setBuffer(bytes);
String str = kryo.readObject(in,String.class);
in.close();
KryoPool.getInstance().returnToPool(kryo);
return str;
}
示例5: KryoSerialization
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的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: deserialize
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
/**
* Deserializes given byte buffer to Object using Kryo instance in pool.
*
* @param buffer input with serialized bytes
* @param <T> deserialized Object type
* @return deserialized Object
*/
public <T> T deserialize(final ByteBuffer buffer) {
ByteBufferInput in = new ByteBufferInput(buffer);
Kryo kryo = borrow();
try {
@SuppressWarnings("unchecked")
T obj = (T) kryo.readClassAndObject(in);
return obj;
} finally {
release(kryo);
}
}
示例7: KryoSerialization
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的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();
}
示例8: main
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的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);
}
示例9: load
import com.esotericsoftware.kryo.io.ByteBufferInput; //导入依赖的package包/类
public static <T> T load (Class<T> type) {
Input input = new ByteBufferInput(output.getBuffer());
return kryo.readObjectOrNull(input, type);
}