Search in sources :

Example 26 with Input

use of com.esotericsoftware.kryo.io.Input in project potato by eyeem.

the class KryoTransportLayer method loadSync.

public boolean loadSync(Storage.List storageList) {
    Kryo kyro = new Kryo();
    Storage storage = storageList.getStorage();
    Class klazz = storage.classname();
    try {
        Input input = new Input(new FileInputStream(filename(storageList)));
        HashMap<String, Object> data = kyro.readObject(input, HashMap.class);
        ArrayList list = (ArrayList) data.get("list");
        input.close();
        Storage.List transaction = storageList.transaction();
        transaction.meta = (HashMap<String, Object>) data.get("meta");
        // don't add objects that already exist in cache as they're most likely fresher
        for (Object loadedObject : list) {
            Object storedObject = storage.get(storage.id(loadedObject));
            transaction.add(storedObject != null ? storedObject : loadedObject);
        }
        transaction.commit(new Storage.Subscription.Action(Storage.Subscription.LOADED));
        return true;
    } catch (FileNotFoundException e) {
        // clean up
        deleteFilesRecursively(getBaseDir(klazz), klazz);
        Log.w(klazz.getSimpleName(), "load() error: file " + filename(storageList) + " missing");
    } catch (Throwable e) {
        Log.e(klazz.getSimpleName(), "load() error", e);
    }
    // prolly should be other thing
    storageList.publish(new Storage.Subscription.Action(Storage.Subscription.LOADED));
    return false;
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Input(com.esotericsoftware.kryo.io.Input) ObjectStreamClass(java.io.ObjectStreamClass) Kryo(com.esotericsoftware.kryo.Kryo)

Example 27 with Input

use of com.esotericsoftware.kryo.io.Input in project carbonite by eveliotc.

the class KryoSerializer method read.

@Override
public T read(InputStream in) {
    Input input = null;
    try {
        input = new Input(in);
        return mKryo.readObjectOrNull(input, mType);
    } finally {
        Util.closeSilently(input);
        Util.closeSilently(in);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Example 28 with Input

use of com.esotericsoftware.kryo.io.Input in project quasar by puniverse.

the class KryoSerializer method read.

public <T> T read(InputStream is, Class<T> type) {
    final Input in = getInput();
    in.setInputStream(is);
    return kryo.readObjectOrNull(input, type);
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Example 29 with Input

use of com.esotericsoftware.kryo.io.Input in project quasar by puniverse.

the class KryoSerializer method read.

@Override
public Object read(InputStream is) throws IOException {
    final Input in = getInput();
    in.setInputStream(is);
    return kryo.readClassAndObject(in);
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Example 30 with Input

use of com.esotericsoftware.kryo.io.Input in project jstorm by alibaba.

the class KryoTupleDeserializer method deserializeTaskId.

/**
     * just get target taskId
     * 
     * @param ser
     * @return
     */
public static int deserializeTaskId(byte[] ser) {
    Input _kryoInput = new Input(1);
    _kryoInput.setBuffer(ser);
    int targetTaskId = _kryoInput.readInt();
    return targetTaskId;
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)49 Kryo (com.esotericsoftware.kryo.Kryo)31 Output (com.esotericsoftware.kryo.io.Output)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Test (org.junit.Test)8 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ArrayList (java.util.ArrayList)2 HiveKey (org.apache.hadoop.hive.ql.io.HiveKey)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2