use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.
the class PSUtilsTest method testWriteTwoKryo.
@Test(expectedExceptions = UserException.CouldNotCreateOutputFile.class)
@SuppressWarnings("unchecked")
public void testWriteTwoKryo() throws Exception {
final File tempFile = createTempFile("test", ".dat");
final Integer int_in = 29382;
final String str_in = "test string";
PSUtils.writeKryoTwo(tempFile.getPath(), int_in, str_in);
final Kryo kryo = new Kryo();
kryo.setReferences(false);
final Input input = new Input(BucketUtils.openFile(tempFile.getPath()));
final Integer int_out = (Integer) kryo.readClassAndObject(input);
final String str_out = (String) kryo.readClassAndObject(input);
input.close();
Assert.assertEquals(int_in, int_out);
Assert.assertEquals(str_in, str_out);
// Point to a subdir that does not exist, so that we get a FNF excpetion
PSUtils.writeKryoTwo(tempFile.getAbsolutePath() + "/bad_dir/bad_subdir/", int_out, str_out);
}
use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.
the class PathSeqKmerSparkIntegrationTest method test.
@SuppressWarnings("unchecked")
@Test(groups = "spark")
public void test() throws Exception {
final File expectedFile = getTestFile("kmer.hss");
final File ref = getTestFile("hg19mini.fasta");
final File output = createTempFile("test", ".hss");
if (!output.delete()) {
Assert.fail();
}
final ArgumentsBuilder args = new ArgumentsBuilder();
args.addFileArgument("reference", ref);
args.addOutput(output);
this.runCommandLine(args.getArgsArray());
Input input_expected = new Input(FileUtils.openInputStream(expectedFile));
Input input_test = new Input(FileUtils.openInputStream(output));
Kryo kryo = new Kryo();
kryo.setReferences(false);
Set<SVKmer> expectedKmerLib = (HopscotchSet<SVKmer>) kryo.readClassAndObject(input_expected);
Set<SVKmer> testKmerLib = (HopscotchSet<SVKmer>) kryo.readClassAndObject(input_test);
Assert.assertEquals(expectedKmerLib, testKmerLib);
}
use of com.esotericsoftware.kryo.io.Input in project ignite by apache.
the class GridMarshallerPerformanceTest method testKryo.
/**
* @throws Exception If failed.
*/
public void testKryo() throws Exception {
final Kryo kryo = new Kryo();
final ByteArrayOutputStream out = new ByteArrayOutputStream();
IgniteInClosure<TestObject> writer = new CI1<TestObject>() {
@Override
public void apply(TestObject obj) {
out.reset();
Output kryoOut = null;
try {
kryoOut = new Output(out);
kryo.writeObject(kryoOut, obj);
} finally {
U.close(kryoOut, log);
}
}
};
IgniteOutClosure<TestObject> reader = new CO<TestObject>() {
@Override
public TestObject apply() {
Input kryoIn = null;
try {
kryoIn = new Input(new ByteArrayInputStream(out.toByteArray()));
return kryo.readObject(kryoIn, TestObject.class);
} finally {
U.close(kryoIn, log);
}
}
};
runTest("Kryo", writer, reader);
}
use of com.esotericsoftware.kryo.io.Input in project ignite by apache.
the class KryoSerializer method deserialize.
/**
* {@inheritDoc}
*/
@Override
public Object deserialize(ByteBuffer buf) {
ByteArrayInputStream stream = null;
Input in = null;
try {
stream = new ByteArrayInputStream(buf.array());
in = new Input(stream);
return kryos.get().readClassAndObject(in);
} catch (Throwable e) {
throw new IllegalStateException("Failed to deserialize object from byte stream", e);
} finally {
U.closeQuiet(in);
U.closeQuiet(stream);
}
}
use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.
the class AbstractFileInputOperatorTest method checkpoint.
/**
* This method checkpoints the given operator.
* @param oper The operator to checkpoint.
* @param bos The ByteArrayOutputStream which saves the checkpoint data temporarily.
* @return new operator.
*/
public static <T> T checkpoint(T oper, ByteArrayOutputStream bos) throws Exception {
Kryo kryo = new Kryo();
Output loutput = new Output(bos);
kryo.writeObject(loutput, oper);
loutput.close();
Input lInput = new Input(bos.toByteArray());
@SuppressWarnings("unchecked") T checkPointedOper = kryo.readObject(lInput, (Class<T>) oper.getClass());
lInput.close();
return checkPointedOper;
}
Aggregations