Search in sources :

Example 1 with OutputChunked

use of com.esotericsoftware.kryo.io.OutputChunked in project alluxio by Alluxio.

the class JournalUtils method writeToCheckpoint.

/**
 * Writes a composite checkpoint for the given checkpointed components.
 *
 * This is the complement of {@link #restoreFromCheckpoint(CheckpointInputStream, List)}.
 *
 * @param output the stream to write to
 * @param components the components to checkpoint
 */
public static void writeToCheckpoint(OutputStream output, List<? extends Checkpointed> components) throws IOException, InterruptedException {
    OutputChunked chunked = new OutputChunked(new CheckpointOutputStream(output, CheckpointType.COMPOUND), 64 * Constants.KB);
    for (Checkpointed component : components) {
        chunked.writeString(component.getCheckpointName().toString());
        component.writeToCheckpoint(chunked);
        chunked.endChunks();
    }
    chunked.flush();
}
Also used : CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) Checkpointed(alluxio.master.journal.checkpoint.Checkpointed) OutputChunked(com.esotericsoftware.kryo.io.OutputChunked)

Example 2 with OutputChunked

use of com.esotericsoftware.kryo.io.OutputChunked in project beam by apache.

the class KryoCoder method encode.

@Override
public void encode(T value, OutputStream outStream) throws IOException {
    final KryoState kryoState = KryoState.get(this);
    if (value == null) {
        throw new CoderException("Cannot encode a null value.");
    }
    final OutputChunked outputChunked = kryoState.getOutputChunked();
    outputChunked.setOutputStream(outStream);
    try {
        kryoState.getKryo().writeClassAndObject(outputChunked, value);
        outputChunked.endChunks();
        outputChunked.flush();
    } catch (KryoException e) {
        outputChunked.clear();
        if (e.getCause() instanceof EOFException) {
            throw (EOFException) e.getCause();
        }
        throw new CoderException("Cannot encode given object of type [" + value.getClass() + "].", e);
    } catch (IllegalArgumentException e) {
        String message = e.getMessage();
        if (message != null) {
            if (message.startsWith("Class is not registered")) {
                throw new CoderException(message);
            }
        }
        throw e;
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) OutputChunked(com.esotericsoftware.kryo.io.OutputChunked) EOFException(java.io.EOFException) CoderException(org.apache.beam.sdk.coders.CoderException)

Aggregations

OutputChunked (com.esotericsoftware.kryo.io.OutputChunked)2 CheckpointOutputStream (alluxio.master.journal.checkpoint.CheckpointOutputStream)1 Checkpointed (alluxio.master.journal.checkpoint.Checkpointed)1 KryoException (com.esotericsoftware.kryo.KryoException)1 EOFException (java.io.EOFException)1 CoderException (org.apache.beam.sdk.coders.CoderException)1