use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class FieldValueSerializableGenerator method deserializeObject.
public Object deserializeObject(byte[] bytes) {
Object obj = getKryo().readClassAndObject(new Input(bytes));
if (fieldGetterMap == null || fieldGetterMap.isEmpty()) {
return obj;
}
// the obj in fact is a map, convert from map to object
try {
Map valueMap = (Map) obj;
obj = clazz.newInstance();
for (Map.Entry<T, Setter<Object, Object>> entry : fieldSetterMap.entrySet()) {
T fieldInfo = entry.getKey();
Setter<Object, Object> setter = entry.getValue();
if (setter != null) {
setter.set(obj, valueMap.get(fieldInfo.getColumnName()));
}
}
return obj;
} catch (Exception e) {
logger.warn("Coverting map to obj exception. ", e);
return obj;
}
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class Gen method cloneObject.
// processStats
/**
* Clone object by serializing and deserializing using Kryo.
* Note this is different from using {@link Kryo#copy(Object)}, which will attempt to also clone transient fields.
*
* @param kryo kryo object used to clone objects
* @param src src object that copy from
* @return cloned object
*/
@SuppressWarnings("unchecked")
private static <SRC> SRC cloneObject(Kryo kryo, SRC src) {
kryo.setClassLoader(src.getClass().getClassLoader());
ByteArrayOutputStream bos = null;
Output output;
Input input = null;
try {
bos = new ByteArrayOutputStream();
output = new Output(bos);
kryo.writeObject(output, src);
output.close();
input = new Input(bos.toByteArray());
return (SRC) kryo.readObject(input, src.getClass());
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(bos);
}
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class KryoSerializableStreamCodec method fromByteArray.
@Override
public Object fromByteArray(Slice fragment) {
ByteArrayInputStream is = new ByteArrayInputStream(fragment.buffer, fragment.offset, fragment.length);
Input input = new Input(is);
return kryo.readClassAndObject(input);
}
Aggregations