use of com.esotericsoftware.kryo.io.Output 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;
}
}
}
use of com.esotericsoftware.kryo.io.Output in project hive by apache.
the class KryoMessageCodec method encode.
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf buf) throws Exception {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
Output kryoOut = new Output(bytes);
kryos.get().writeClassAndObject(kryoOut, msg);
kryoOut.flush();
byte[] msgData = maybeEncrypt(bytes.toByteArray());
LOG.debug("Encoded message of type {} ({} bytes)", msg.getClass().getName(), msgData.length);
checkSize(msgData.length);
buf.ensureWritable(msgData.length + 4);
buf.writeInt(msgData.length);
buf.writeBytes(msgData);
}
use of com.esotericsoftware.kryo.io.Output in project Paper by pilgr.
the class DbStoragePlainFile method writeTableFile.
/**
* Attempt to write the file, delete the backup and return true as atomically as
* possible. If any exception occurs, delete the new file; next time we will restore
* from the backup.
*
* @param key table key
* @param paperTable table instance
* @param originalFile file to write new data
* @param backupFile backup file to be used if write is failed
*/
private <E> void writeTableFile(String key, PaperTable<E> paperTable, File originalFile, File backupFile) {
try {
FileOutputStream fileStream = new FileOutputStream(originalFile);
final Output kryoOutput = new Output(fileStream);
getKryo().writeObject(kryoOutput, paperTable);
kryoOutput.flush();
fileStream.flush();
sync(fileStream);
//also close file stream
kryoOutput.close();
// Writing was successful, delete the backup file if there is one.
//noinspection ResultOfMethodCallIgnored
backupFile.delete();
} catch (IOException | KryoException e) {
// Clean up an unsuccessfully written file
if (originalFile.exists()) {
if (!originalFile.delete()) {
throw new PaperDbException("Couldn't clean up partially-written file " + originalFile, e);
}
}
throw new PaperDbException("Couldn't save table: " + key + ". " + "Backed up table will be used on next read attempt", e);
}
}
use of com.esotericsoftware.kryo.io.Output in project heron by twitter.
the class KryoSerializer method initialize.
@Override
public void initialize(Map<String, Object> config) {
kryo = new Kryo();
kryo.setReferences(false);
kryoOut = new Output(2000, 2000000000);
kryoIn = new Input(1);
}
use of com.esotericsoftware.kryo.io.Output in project heron by twitter.
the class HeronPluggableSerializerDelegate method initialize.
@Override
@SuppressWarnings("rawtypes")
public void initialize(Map config) {
kryo = SerializationFactory.getKryo(config);
kryoOut = new Output(2000, 2000000000);
kryoIn = new Input(1);
}
Aggregations