Search in sources :

Example 46 with Input

use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.

the class BreakpointEvidenceTest method serializationTest.

@Test(groups = "spark")
void serializationTest() {
    final List<BreakpointEvidence> evidenceList = new ArrayList<>(7);
    final SAMFileHeader samHeader = ArtificialReadUtils.createArtificialSamHeader();
    final ReadMetadata.ReadGroupFragmentStatistics groupStatistics = new ReadMetadata.ReadGroupFragmentStatistics(400, 175, 20);
    final ReadMetadata metadata = new ReadMetadata(Collections.emptySet(), samHeader, groupStatistics, 1, 2L, 2L, 1);
    final List<GATKRead> readPair = ArtificialReadUtils.createPair(samHeader, "firstReadPair", 101, 1010, 1382, false, false);
    final GATKRead read = readPair.get(0);
    evidenceList.add(new BreakpointEvidence.SplitRead(read, metadata, true));
    evidenceList.add(new BreakpointEvidence.LargeIndel(read, metadata, read.getStart() + 50));
    evidenceList.add(new BreakpointEvidence.MateUnmapped(read, metadata));
    evidenceList.add(new BreakpointEvidence.InterContigPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.OutiesPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.SameStrandPair(read, metadata));
    evidenceList.add(new BreakpointEvidence.WeirdTemplateSize(read, metadata));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, evidenceList);
    out.flush();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    final Input in = new Input(bis);
    @SuppressWarnings("unchecked") final List<BreakpointEvidence> evidenceList2 = (List<BreakpointEvidence>) kryo.readClassAndObject(in);
    Assert.assertEquals(evidenceList.size(), evidenceList2.size());
    for (int idx = 0; idx != evidenceList.size(); ++idx) {
        Assert.assertEquals(evidenceList.get(idx).toString(), evidenceList2.get(idx).toString());
    }
}
Also used : GATKRead(org.broadinstitute.hellbender.utils.read.GATKRead) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ArrayList(java.util.ArrayList) List(java.util.List) SAMFileHeader(htsjdk.samtools.SAMFileHeader) Kryo(com.esotericsoftware.kryo.Kryo) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 47 with Input

use of com.esotericsoftware.kryo.io.Input in project gatk by broadinstitute.

the class NovelAdjacencyReferenceLocationsUnitTest method seeIfItWorks.

private static void seeIfItWorks(final NovelAdjacencyReferenceLocations breakpoints, final NovelAdjacencyReferenceLocations.EndConnectionType expectedEndConnectionType, final SimpleInterval expectedLeftBreakpoint, final SimpleInterval expectedRightBreakpoint, final SimpleInterval expectedRepeatUnitRefSpan, final String expectedHomology, final String expectedInsertion, final int expectedRefDupNum, final int expectedCtgDupNum, final List<String> expectedTandupCigarStrings) {
    Assert.assertEquals(breakpoints.leftJustifiedLeftRefLoc, expectedLeftBreakpoint);
    Assert.assertEquals(breakpoints.leftJustifiedRightRefLoc, expectedRightBreakpoint);
    Assert.assertEquals(breakpoints.endConnectionType, expectedEndConnectionType);
    Assert.assertEquals(breakpoints.complication.getHomologyForwardStrandRep(), expectedHomology);
    Assert.assertEquals(breakpoints.complication.getInsertedSequenceForwardStrandRep(), expectedInsertion);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatUnitRefSpan(), expectedRepeatUnitRefSpan);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatNumOnRef(), expectedRefDupNum);
    Assert.assertEquals(breakpoints.complication.getDupSeqRepeatNumOnCtg(), expectedCtgDupNum);
    Assert.assertEquals(breakpoints.complication.getCigarStringsForDupSeqOnCtg(), expectedTandupCigarStrings);
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final Output out = new Output(bos);
    final Kryo kryo = new Kryo();
    kryo.writeClassAndObject(out, breakpoints);
    out.flush();
    final ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
    final Input in = new Input(bis);
    @SuppressWarnings("unchecked") final NovelAdjacencyReferenceLocations roundTrip = (NovelAdjacencyReferenceLocations) kryo.readClassAndObject(in);
    Assert.assertEquals(roundTrip, breakpoints);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 48 with Input

use of com.esotericsoftware.kryo.io.Input in project cdap by caskdata.

the class KryoSerializerTest method testSchemaSerializer.

@Test
public void testSchemaSerializer() {
    Schema schema = createSchema();
    Kryo kryo = new Kryo();
    kryo.addDefaultSerializer(Schema.class, SchemaSerializer.class);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try (Output output = new Output(bos)) {
        kryo.writeObject(output, schema);
    }
    Input input = new Input(bos.toByteArray());
    Schema newSchema = kryo.readObject(input, Schema.class);
    Assert.assertEquals(schema, newSchema);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Schema(co.cask.cdap.api.data.schema.Schema) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 49 with Input

use of com.esotericsoftware.kryo.io.Input in project chuidiang-ejemplos by chuidiang.

the class KryoExample method main.

public static void main(String[] args) {
    Kryo serializer = new Kryo();
    // It's necessary for classes without default constructor
    serializer.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    Output os = new Output(byteStream);
    SomeLittleClass instance = SomeLittleClass.newInstance(2);
    serializer.writeObject(os, instance);
    os.close();
    System.out.println(byteStream.toByteArray().length);
    Input input = new Input(byteStream.toByteArray());
    SomeLittleClass read = serializer.readObject(input, SomeLittleClass.class);
    System.out.println(read.toString());
    byteStream = new ByteArrayOutputStream();
    os = new Output(byteStream);
    SomeMediumClass mediumClass = new SomeMediumClass();
    serializer.writeObject(os, mediumClass);
    os.close();
    System.out.println(byteStream.toByteArray().length);
    input = new Input(byteStream.toByteArray());
    SomeMediumClass mediumClassRead = serializer.readObject(input, SomeMediumClass.class);
    System.out.println(mediumClassRead);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)49 Kryo (com.esotericsoftware.kryo.Kryo)31 Output (com.esotericsoftware.kryo.io.Output)21 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)15 Test (org.junit.Test)8 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ArrayList (java.util.ArrayList)2 HiveKey (org.apache.hadoop.hive.ql.io.HiveKey)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2