use of com.esotericsoftware.kryo.io.Output in project cas by apereo.
the class KryoTranscoder method encode.
@Override
public CachedData encode(final Object obj) {
final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
try (Output output = new Output(byteStream)) {
this.kryo.writeClassAndObject(output, obj);
output.flush();
final byte[] bytes = byteStream.toByteArray();
return new CachedData(0, bytes, bytes.length);
}
}
use of com.esotericsoftware.kryo.io.Output in project potato by eyeem.
the class KryoTransportLayer method saveSync.
public boolean saveSync(Storage.List list, int limit) {
Class klazz = null;
try {
klazz = list.getStorage().classname();
File dir = new File(dirname(klazz));
dir.mkdirs();
Kryo kyro = new Kryo();
Output output;
HashMap<String, Object> data = new HashMap<String, Object>();
data.put("list", list.toArrayList(limit));
data.put("meta", list.meta);
output = new Output(new FileOutputStream(filename(list)));
kyro.writeObject(output, data);
output.close();
return true;
} catch (Throwable e) {
if (klazz != null)
Log.e(klazz.getSimpleName(), "save() error", e);
return false;
}
}
use of com.esotericsoftware.kryo.io.Output in project carbonite by eveliotc.
the class KryoSerializer method write.
@Override
public boolean write(OutputStream out, T value) {
Output output = null;
try {
output = new Output(out);
mKryo.writeObjectOrNull(output, value, mType);
return true;
} finally {
Util.closeSilently(output);
Util.closeSilently(out);
}
}
use of com.esotericsoftware.kryo.io.Output in project jersey by jersey.
the class KryoMessageBodyProvider method writeTo.
@Override
public void writeTo(final Object object, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException {
final Output output = new Output(entityStream);
kryoPool.run(new KryoCallback() {
public Object execute(Kryo kryo) {
kryo.writeObject(output, object);
return null;
}
});
output.flush();
}
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);
}
}
Aggregations