Search in sources :

Example 6 with Output

use of com.esotericsoftware.kryo.io.Output in project quasar by puniverse.

the class KryoSerializer method write.

@Override
public void write(OutputStream os, Object object) {
    final Output out = getOutput();
    out.clear();
    out.setOutputStream(os);
    kryo.writeClassAndObject(out, object);
    out.flush();
    out.setOutputStream(null);
}
Also used : Output(com.esotericsoftware.kryo.io.Output)

Example 7 with Output

use of com.esotericsoftware.kryo.io.Output in project quasar by puniverse.

the class KryoSerializer method write.

@Override
public byte[] write(Object object) {
    final Output out = getOutput();
    out.clear();
    kryo.writeClassAndObject(out, object);
    out.flush();
    return out.toBytes();
}
Also used : Output(com.esotericsoftware.kryo.io.Output)

Example 8 with Output

use of com.esotericsoftware.kryo.io.Output in project Gaffer by gchq.

the class RegistratorTest method testEntity.

@Test
public void testEntity() {
    // Given
    Entity entity = new Entity("group");
    entity.setVertex("abc");
    entity.putProperty("property1", 1);
    // When
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output output = new Output(baos);
    kryo.writeObject(output, entity);
    output.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Input input = new Input(bais);
    Entity read = kryo.readObject(input, Entity.class);
    input.close();
    // Then
    assertEquals(entity, read);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 9 with Output

use of com.esotericsoftware.kryo.io.Output in project Gaffer by gchq.

the class RegistratorTest method testEdge.

@Test
public void testEdge() {
    // Given
    Edge edge = new Edge("group");
    edge.setSource("abc");
    edge.setDestination("xyz");
    edge.setDirected(true);
    edge.putProperty("property1", 1);
    // When
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output output = new Output(baos);
    kryo.writeObject(output, edge);
    output.close();
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    Input input = new Input(bais);
    Edge read = kryo.readObject(input, Edge.class);
    input.close();
    // Then
    assertEquals(edge, read);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteArrayInputStream(java.io.ByteArrayInputStream) Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 10 with Output

use of com.esotericsoftware.kryo.io.Output in project MantaroBot by Mantaro.

the class KryoUtils method serialize.

public static byte[] serialize(Kryo kryo, Object obj) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Output out = new Output(baos);
    checkNotNull(kryo, "kryo").writeClassAndObject(out, obj);
    out.close();
    return baos.toByteArray();
}
Also used : Output(com.esotericsoftware.kryo.io.Output) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

Output (com.esotericsoftware.kryo.io.Output)51 Kryo (com.esotericsoftware.kryo.Kryo)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)22 Input (com.esotericsoftware.kryo.io.Input)21 ByteArrayInputStream (java.io.ByteArrayInputStream)12 Test (org.junit.Test)8 FileOutputStream (java.io.FileOutputStream)7 Test (org.testng.annotations.Test)6 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 KryoException (com.esotericsoftware.kryo.KryoException)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 SAMFileHeader (htsjdk.samtools.SAMFileHeader)3 Schema (co.cask.cdap.api.data.schema.Schema)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 HashMap (java.util.HashMap)2 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)2 StructuredRecord (co.cask.cdap.api.data.format.StructuredRecord)1 ClassIdPair (com.datatorrent.stram.codec.DefaultStatefulStreamCodec.ClassIdPair)1