Java 类com.esotericsoftware.kryo.io.ByteBufferInput 实例源码

项目:proteus-consumer-couchbase    文件:ProteusSerializer.java   
@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);
    }
}
项目:athena    文件:KryoNamespace.java   
/**
 * 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);
    }
}
项目:athena    文件:KryoNamespace.java   
/**
 * Deserializes given InputStream to an Object using Kryo instance in pool.
 *
 * @param stream input stream
 * @param <T> deserialized Object type
 * @return deserialized Object
 * @param bufferSize size of the buffer in front of the stream
 */
public <T> T deserialize(final InputStream stream, final int bufferSize) {
    ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
项目:kafka-serializer-example    文件:KryoReadingSerializer.java   
@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);
    }
}
项目:ravikumaran201504    文件:KryoNamespace.java   
/**
 * 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);
    }
}
项目:ravikumaran201504    文件:KryoNamespace.java   
/**
 * Deserializes given InputStream to an Object using Kryo instance in pool.
 *
 * @param stream input stream
 * @param <T> deserialized Object type
 * @return deserialized Object
 * @param bufferSize size of the buffer in front of the stream
 */
public <T> T deserialize(final InputStream stream, final int bufferSize) {
    ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
项目:hashaggregator    文件:GenericGroupByKey.java   
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;
    }
项目:magic-realm    文件:KryoSerialization.java   
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();
}
项目:atomix    文件:KryoNamespace.java   
/**
 * 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);
  }
}
项目:atomix    文件:KryoNamespace.java   
/**
 * Deserializes given InputStream to an Object using Kryo instance in pool.
 *
 * @param stream     input stream
 * @param <T>        deserialized Object type
 * @param bufferSize size of the buffer in front of the stream
 * @return deserialized Object
 */
public <T> T deserialize(final InputStream stream, final int bufferSize) {
  ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
  Kryo kryo = borrow();
  try {
    @SuppressWarnings("unchecked")
    T obj = (T) kryo.readClassAndObject(in);
    return obj;
  } finally {
    release(kryo);
  }
}
项目:hashaggregator    文件:GenericGroupByKey.java   
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;
    }
项目:the-erder    文件:KryoSerialization.java   
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();
}
项目:onos    文件:KryoNamespace.java   
/**
 * 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);
    }
}
项目:onos    文件:KryoNamespace.java   
/**
 * Deserializes given InputStream to an Object using Kryo instance in pool.
 *
 * @param stream input stream
 * @param <T> deserialized Object type
 * @return deserialized Object
 * @param bufferSize size of the buffer in front of the stream
 */
public <T> T deserialize(final InputStream stream, final int bufferSize) {
    ByteBufferInput in = new ByteBufferInput(stream, bufferSize);
    Kryo kryo = borrow();
    try {
        @SuppressWarnings("unchecked")
        T obj = (T) kryo.readClassAndObject(in);
        return obj;
    } finally {
        release(kryo);
    }
}
项目:kryonet    文件:KryoSerialization.java   
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();
}
项目:hashaggregator    文件:GenericGroupByKeyTest.java   
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);


}
项目:hashaggregator    文件:GenericGroupByKeyTest.java   
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);


}
项目:gdx-ai    文件:KryoUtils.java   
public static <T> T load (Class<T> type) {
    Input input = new ByteBufferInput(output.getBuffer());
    return kryo.readObjectOrNull(input, type);
}