Search in sources :

Example 31 with Output

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);
    }
}
Also used : CachedData(net.spy.memcached.CachedData) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 32 with Output

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;
    }
}
Also used : HashMap(java.util.HashMap) Output(com.esotericsoftware.kryo.io.Output) FileOutputStream(java.io.FileOutputStream) ObjectStreamClass(java.io.ObjectStreamClass) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo)

Example 33 with Output

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);
    }
}
Also used : Output(com.esotericsoftware.kryo.io.Output)

Example 34 with Output

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();
}
Also used : Output(com.esotericsoftware.kryo.io.Output) KryoCallback(com.esotericsoftware.kryo.pool.KryoCallback) Kryo(com.esotericsoftware.kryo.Kryo)

Example 35 with Output

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);
    }
}
Also used : KryoException(com.esotericsoftware.kryo.KryoException) FileOutputStream(java.io.FileOutputStream) Output(com.esotericsoftware.kryo.io.Output) IOException(java.io.IOException)

Aggregations

Output (com.esotericsoftware.kryo.io.Output)51 Kryo (com.esotericsoftware.kryo.Kryo)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Input (com.esotericsoftware.kryo.io.Input)21 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Test (org.junit.Test)8 FileOutputStream (java.io.FileOutputStream)7 Test (org.testng.annotations.Test)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 KryoException (com.esotericsoftware.kryo.KryoException)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 Schema (co.cask.cdap.api.data.schema.Schema)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)1 ClassIdPair (com.datatorrent.stram.codec.DefaultStatefulStreamCodec.ClassIdPair)1