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);
}
}
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()));
}
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);
}
}
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;
}
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);
}
Aggregations