Java源码示例:com.esotericsoftware.kryo.io.ByteBufferInput

示例1
@Override
public ParaflowRecord transform(byte[] value, int partition)
{
    Input input = new ByteBufferInput(value);
    try {
        LineOrder lineOrder = kryo.readObject(input, LineOrder.class);
        lineOrder.setFiberId(partition);
        long custKey = lineOrder.getCustomerKey();
        lineOrder.setKey(custKey);
        lineOrder.setTimestamp(lineOrder.getCreation());
        input.close();
        return lineOrder;
    }
    catch (Exception e) {
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);
        logger.error(stringWriter.toString());
        e.printStackTrace();
        return null;
    }
}
 
示例2
@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);
    }
}
 
示例3
public static Input getInput(InputBuf inputBuf) {
    ByteBuffer nioBuf = inputBuf.nioByteBuffer();
    ByteBufferInput input = new ByteBufferInput();
    input.setVarIntsEnabled(false); // Compatible with FastInput
    input.setBuffer(nioBuf, 0, nioBuf.capacity());
    return input;
}
 
示例4
/**
 * 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);
  }
}
 
示例5
/**
 * 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);
  }
}
 
示例6
/**
 * 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
/**
 * 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);
    }
}
 
示例8
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();
}
 
示例9
UserAgentAnalyzerTester deserialize(byte[] bytes) {
    Kryo            kryo            = new Kryo();
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (UserAgentAnalyzerTester) kryo.readClassAndObject(byteBufferInput);
}
 
示例10
MatcherList deserialize(byte[] bytes) {
    Kryo            kryo            = new Kryo();
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (MatcherList) kryo.readClassAndObject(byteBufferInput);
}
 
示例11
public static <T> T load (Class<T> type) {
	Input input = new ByteBufferInput(output.getBuffer());
	return kryo.readObjectOrNull(input, type);
}