com.esotericsoftware.kryo.io.ByteBufferInput Java Examples

The following examples show how to use com.esotericsoftware.kryo.io.ByteBufferInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TpchDataTransformer.java    From paraflow with Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example #2
Source File: KryoReadingSerializer.java    From kafka-serializer-example with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #3
Source File: Inputs.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: Namespace.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #5
Source File: Namespace.java    From atomix with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #6
Source File: KryoNamespace.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #7
Source File: KryoNamespace.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #8
Source File: KryoSerialization.java    From kryonet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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();
}
 
Example #9
Source File: TestKryoSerialization.java    From yauaa with Apache License 2.0 4 votes vote down vote up
UserAgentAnalyzerTester deserialize(byte[] bytes) {
    Kryo            kryo            = new Kryo();
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (UserAgentAnalyzerTester) kryo.readClassAndObject(byteBufferInput);
}
 
Example #10
Source File: TestMatcherList.java    From yauaa with Apache License 2.0 4 votes vote down vote up
MatcherList deserialize(byte[] bytes) {
    Kryo            kryo            = new Kryo();
    ByteBufferInput byteBufferInput = new ByteBufferInput(bytes);
    return (MatcherList) kryo.readClassAndObject(byteBufferInput);
}
 
Example #11
Source File: KryoUtils.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
public static <T> T load (Class<T> type) {
	Input input = new ByteBufferInput(output.getBuffer());
	return kryo.readObjectOrNull(input, type);
}