use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class AbstractFileInputOperatorTest method restoreCheckPoint.
/**
* Restores the checkpointed operator.
* @param checkPointOper The checkpointed operator.
* @param bos The ByteArrayOutputStream which saves the checkpoint data temporarily.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> T restoreCheckPoint(T checkPointOper, ByteArrayOutputStream bos) throws Exception {
Kryo kryo = new Kryo();
Input lInput = new Input(bos.toByteArray());
T oper = kryo.readObject(lInput, (Class<T>) checkPointOper.getClass());
lInput.close();
return oper;
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class KryoCloneUtils method getClones.
/**
* Clone array of objects from source object
* @param num size of the return array
* @return array of T
*/
@SuppressWarnings("unchecked")
public T[] getClones(int num) {
T[] ts = (T[]) Array.newInstance(clazz, num);
try (Input input = new Input(bin)) {
for (int i = 0; i < ts.length; i++) {
input.rewind();
ts[i] = kryo.readObject(input, clazz);
}
}
return ts;
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class KryoCloneUtils method cloneObject.
/**
* 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
*/
@SuppressWarnings("unchecked")
public 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 GeodeCheckpointStore method get.
/**
* Return the value for specified key from Geode region
*
* @return the value object
*/
@Override
public Object get(Object key) {
try {
byte[] obj = getGeodeRegion().get((String) key);
if (obj == null) {
return null;
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(obj);
getKyro().setClassLoader(Thread.currentThread().getContextClassLoader());
Input input = new Input(byteArrayInputStream);
return getKyro().readClassAndObject(input);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class CollectionSerdeTest method testSerdeSet.
@Test
public void testSerdeSet() {
CollectionSerde<String, Set<String>> serdeSet = new CollectionSerde<>(new StringSerde(), (Class) HashSet.class);
Set<String> stringList = Sets.newHashSet("a", "b", "c");
SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
serdeSet.serialize(stringList, buffer);
Slice slice = buffer.toSlice();
Set<String> deserializedSet = serdeSet.deserialize(new Input(slice.buffer, slice.offset, slice.length));
Assert.assertEquals(stringList, deserializedSet);
}
Aggregations