use of com.esotericsoftware.kryo.io.Input in project MantaroBot by Mantaro.
the class KryoUtils method unserialize.
public static Object unserialize(Kryo kryo, byte[] data) {
Input in = new Input(new ByteArrayInputStream(checkNotNull(data, "data")));
Object o = checkNotNull(kryo, "kryo").readClassAndObject(in);
in.close();
return o;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class SerializationUtilities method deserializeObjectFromKryo.
private static <T extends Serializable> T deserializeObjectFromKryo(byte[] bytes, Class<T> clazz) {
Input inp = new Input(new ByteArrayInputStream(bytes));
Kryo kryo = borrowKryo();
T func = null;
try {
func = kryo.readObject(inp, clazz);
} finally {
releaseKryo(kryo);
}
inp.close();
return func;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class SerializationUtilities method deserializeObjectByKryo.
private static <T> T deserializeObjectByKryo(Kryo kryo, InputStream in, Class<T> clazz) {
Input inp = new Input(in);
kryo.setClassLoader(Utilities.getSessionSpecifiedClassLoader());
T t = kryo.readObject(inp, clazz);
inp.close();
return t;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class HiveKVResultCache method next.
public synchronized Tuple2<HiveKey, BytesWritable> next() {
Preconditions.checkState(hasNext());
if (!readBufferUsed) {
try {
if (input == null && output != null) {
// Close output stream if open
output.close();
output = null;
FileInputStream fis = null;
try {
fis = new FileInputStream(tmpFile);
input = new Input(fis);
} finally {
if (input == null && fis != null) {
fis.close();
}
}
}
if (input != null) {
// Load next batch from disk
for (int i = 0; i < IN_MEMORY_NUM_ROWS; i++) {
ObjectPair<HiveKey, BytesWritable> pair = readBuffer[i];
pair.setFirst(readHiveKey(input));
pair.setSecond(readValue(input));
}
if (input.eof()) {
input.close();
input = null;
}
rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
readBufferUsed = true;
readCursor = 0;
} else if (writeCursor == 1) {
ObjectPair<HiveKey, BytesWritable> pair = writeBuffer[0];
Tuple2<HiveKey, BytesWritable> row = new Tuple2<HiveKey, BytesWritable>(pair.getFirst(), pair.getSecond());
pair.setFirst(null);
pair.setSecond(null);
writeCursor = 0;
return row;
} else {
// No record on disk, more data in write buffer
switchBufferAndResetCursor();
}
} catch (Exception e) {
// Clean up the cache
clear();
throw new RuntimeException("Failed to load rows from disk", e);
}
}
ObjectPair<HiveKey, BytesWritable> pair = readBuffer[readCursor];
Tuple2<HiveKey, BytesWritable> row = new Tuple2<HiveKey, BytesWritable>(pair.getFirst(), pair.getSecond());
pair.setFirst(null);
pair.setSecond(null);
if (++readCursor >= rowsInReadBuffer) {
readBufferUsed = false;
rowsInReadBuffer = 0;
readCursor = 0;
}
return row;
}
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;
}
Aggregations