Search in sources :

Example 36 with Input

use of com.esotericsoftware.kryo.io.Input in project carbonite by eveliotc.

the class KryoSerializer method read.

@Override
public T read(InputStream in) {
    Input input = null;
    try {
        input = new Input(in);
        return mKryo.readObjectOrNull(input, mType);
    } finally {
        Util.closeSilently(input);
        Util.closeSilently(in);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Example 37 with Input

use of com.esotericsoftware.kryo.io.Input in project storm by apache.

the class BlowfishTupleSerializerTest method testEncryptsAndDecryptsMessage.

/**
     * Reads a string encrypted by another instance with a shared key
     */
@Test
public void testEncryptsAndDecryptsMessage() {
    String testText = "Tetraodontidae is a family of primarily marine and estuarine fish of the order" + " Tetraodontiformes. The family includes many familiar species, which are" + " variously called pufferfish, puffers, balloonfish, blowfish, bubblefish," + " globefish, swellfish, toadfish, toadies, honey toads, sugar toads, and sea" + " squab.[1] They are morphologically similar to the closely related" + " porcupinefish, which have large external spines (unlike the thinner, hidden" + " spines of Tetraodontidae, which are only visible when the fish has puffed up)." + " The scientific name refers to the four large teeth, fused into an upper and" + " lower plate, which are used for crushing the shells of crustaceans and" + " mollusks, their natural prey.";
    Kryo kryo = new Kryo();
    String arbitraryKey = "7dd6fb3203878381b08f9c89d25ed105";
    Map stormConf = ImmutableMap.of(BlowfishTupleSerializer.SECRET_KEY, arbitraryKey);
    BlowfishTupleSerializer writerBTS = new BlowfishTupleSerializer(kryo, stormConf);
    BlowfishTupleSerializer readerBTS = new BlowfishTupleSerializer(kryo, stormConf);
    int bufferSize = 1024;
    Output output = new Output(bufferSize, bufferSize);
    Input input = new Input(bufferSize);
    String[] stringList = testText.split(" ");
    ListDelegate delegate = new ListDelegate();
    delegate.addAll(Arrays.asList(stringList));
    writerBTS.write(kryo, output, delegate);
    input.setBuffer(output.getBuffer());
    ListDelegate outDelegate = readerBTS.read(kryo, input, ListDelegate.class);
    Assert.assertEquals(testText, Joiner.on(" ").join(outDelegate.toArray()));
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output) ListDelegate(org.apache.storm.utils.ListDelegate) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 38 with Input

use of com.esotericsoftware.kryo.io.Input in project hive by apache.

the class KryoMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() < 4) {
        return;
    }
    in.markReaderIndex();
    int msgSize = in.readInt();
    checkSize(msgSize);
    if (in.readableBytes() < msgSize) {
        // Incomplete message in buffer.
        in.resetReaderIndex();
        return;
    }
    try {
        ByteBuffer nioBuffer = maybeDecrypt(in.nioBuffer(in.readerIndex(), msgSize));
        Input kryoIn = new Input(new ByteBufferInputStream(nioBuffer));
        Object msg = kryos.get().readClassAndObject(kryoIn);
        LOG.debug("Decoded message of type {} ({} bytes)", msg != null ? msg.getClass().getName() : msg, msgSize);
        out.add(msg);
    } finally {
        in.skipBytes(msgSize);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ByteBufferInputStream(com.esotericsoftware.kryo.io.ByteBufferInputStream) ByteBuffer(java.nio.ByteBuffer)

Example 39 with Input

use of com.esotericsoftware.kryo.io.Input in project jstorm by alibaba.

the class KryoTupleDeserializer method deserializeTaskId.

/**
     * just get target taskId
     * 
     * @param ser
     * @return
     */
public static int deserializeTaskId(byte[] ser) {
    Input _kryoInput = new Input(1);
    _kryoInput.setBuffer(ser);
    int targetTaskId = _kryoInput.readInt();
    return targetTaskId;
}
Also used : Input(com.esotericsoftware.kryo.io.Input)

Example 40 with Input

use of com.esotericsoftware.kryo.io.Input in project heron by twitter.

the class KryoSerializer method initialize.

@Override
public void initialize(Map<String, Object> config) {
    kryo = new Kryo();
    kryo.setReferences(false);
    kryoOut = new Output(2000, 2000000000);
    kryoIn = new Input(1);
}
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