Search in sources :

Example 1 with DataOutputViewStream

use of org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream in project flink by apache.

the class KryoSerializer method serialize.

@Override
public void serialize(T record, DataOutputView target) throws IOException {
    checkKryoInitialized();
    if (target != previousOut) {
        DataOutputViewStream outputStream = new DataOutputViewStream(target);
        output = new Output(outputStream);
        previousOut = target;
    }
    // otherwise data might be written multiple times in case of a previous EOFException
    if (output.position() != 0) {
        throw new IllegalStateException("The Kryo Output still contains data from a previous " + "serialize call. It has to be flushed or cleared at the end of the serialize call.");
    }
    try {
        kryo.writeClassAndObject(output, record);
        output.flush();
    } catch (KryoException ke) {
        // make sure that the Kryo output buffer is cleared in case that we can recover from
        // the exception (e.g. EOFException which denotes buffer full)
        output.clear();
        Throwable cause = ke.getCause();
        if (cause instanceof EOFException) {
            throw (EOFException) cause;
        } else {
            throw ke;
        }
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) DataOutputViewStream(org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream) Output(com.esotericsoftware.kryo.io.Output) EOFException(java.io.EOFException)

Aggregations

KryoException (com.esotericsoftware.kryo.KryoException)1 Output (com.esotericsoftware.kryo.io.Output)1 EOFException (java.io.EOFException)1 DataOutputViewStream (org.apache.flink.api.java.typeutils.runtime.DataOutputViewStream)1