use of com.esotericsoftware.kryo.io.Input in project storm by apache.
the class KinesisConnectionInfo method getKryoDeserializedObject.
private Object getKryoDeserializedObject(final byte[] ser) {
final Kryo kryo = new Kryo();
final Input input = new Input(new ByteArrayInputStream(ser));
kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
return kryo.readClassAndObject(input);
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class KryoSerializer method deserialize.
public static <T> T deserialize(byte[] buffer, Class<T> clazz) {
Kryo kryo = SerializationUtilities.borrowKryo();
kryo.setClassLoader(Thread.currentThread().getContextClassLoader());
T result = null;
try {
result = kryo.readObject(new Input(new ByteArrayInputStream(buffer)), clazz);
} finally {
SerializationUtilities.releaseKryo(kryo);
}
return result;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class KeyValueContainer method next.
public ObjectPair<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
if (rowsOnDisk >= IN_MEMORY_NUM_ROWS) {
rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
} else {
rowsInReadBuffer = rowsOnDisk;
}
for (int i = 0; i < rowsInReadBuffer; i++) {
ObjectPair<HiveKey, BytesWritable> pair = readBuffer[i];
pair.setFirst(readHiveKey(input));
pair.setSecond(readValue(input));
}
if (input.eof()) {
input.close();
input = null;
}
readBufferUsed = true;
readCursor = 0;
rowsOnDisk -= rowsInReadBuffer;
}
} catch (Exception e) {
// Clean up the cache
clear();
throw new RuntimeException("Failed to load key/value pairs from disk", e);
}
}
ObjectPair<HiveKey, BytesWritable> row = readBuffer[readCursor];
if (++readCursor >= rowsInReadBuffer) {
readBufferUsed = false;
rowsInReadBuffer = 0;
readCursor = 0;
}
return row;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class ObjectContainer method next.
public ROW 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
if (rowsOnDisk >= IN_MEMORY_NUM_ROWS) {
rowsInReadBuffer = IN_MEMORY_NUM_ROWS;
} else {
rowsInReadBuffer = rowsOnDisk;
}
Kryo kryo = SerializationUtilities.borrowKryo();
try {
for (int i = 0; i < rowsInReadBuffer; i++) {
readBuffer[i] = (ROW) kryo.readClassAndObject(input);
}
} finally {
SerializationUtilities.releaseKryo(kryo);
}
if (input.eof()) {
input.close();
input = null;
}
readBufferUsed = true;
readCursor = 0;
rowsOnDisk -= rowsInReadBuffer;
}
} catch (Exception e) {
// Clean up the cache
clear();
throw new RuntimeException("Failed to load rows from disk", e);
}
}
ROW row = readBuffer[readCursor];
if (++readCursor >= rowsInReadBuffer) {
readBufferUsed = false;
rowsInReadBuffer = 0;
readCursor = 0;
}
return row;
}
use of com.esotericsoftware.kryo.io.Input in project hive by apache.
the class FSStatsAggregator method connect.
@Override
public boolean connect(StatsCollectionContext scc) {
List<String> statsDirs = scc.getStatsTmpDirs();
assert statsDirs.size() == 1 : "Found multiple stats dirs: " + statsDirs;
Path statsDir = new Path(statsDirs.get(0));
LOG.debug("About to read stats from : " + statsDir);
statsMap = new HashMap<String, Map<String, String>>();
try {
fs = statsDir.getFileSystem(scc.getHiveConf());
statsList = new ArrayList<Map<String, Map<String, String>>>();
FileStatus[] status = fs.listStatus(statsDir, new PathFilter() {
@Override
public boolean accept(Path file) {
return file.getName().startsWith(StatsSetupConst.STATS_FILE_PREFIX);
}
});
for (FileStatus file : status) {
Input in = new Input(fs.open(file.getPath()));
Kryo kryo = SerializationUtilities.borrowKryo();
try {
statsMap = kryo.readObject(in, statsMap.getClass());
} finally {
SerializationUtilities.releaseKryo(kryo);
}
LOG.info("Read stats : " + statsMap);
statsList.add(statsMap);
in.close();
}
return true;
} catch (IOException e) {
LOG.error("Failed to read stats from filesystem ", e);
return false;
}
}
Aggregations