Search in sources :

Example 56 with Input

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);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 57 with Input

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);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) HopscotchSet(org.broadinstitute.hellbender.tools.spark.utils.HopscotchSet) SVKmer(org.broadinstitute.hellbender.tools.spark.sv.SVKmer) ArgumentsBuilder(org.broadinstitute.hellbender.utils.test.ArgumentsBuilder) File(java.io.File) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 58 with Input

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);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ObjectInput(java.io.ObjectInput) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ObjectOutput(java.io.ObjectOutput) CI1(org.apache.ignite.internal.util.typedef.CI1) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CO(org.apache.ignite.internal.util.typedef.CO) Kryo(com.esotericsoftware.kryo.Kryo)

Example 59 with Input

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);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 60 with Input

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;
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)73 Kryo (com.esotericsoftware.kryo.Kryo)37 Output (com.esotericsoftware.kryo.io.Output)28 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 Test (org.junit.Test)19 Slice (com.datatorrent.netlet.util.Slice)9 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ObjectInput (java.io.ObjectInput)2