本文整理汇总了Java中com.esotericsoftware.kryo.io.UnsafeInput类的典型用法代码示例。如果您正苦于以下问题:Java UnsafeInput类的具体用法?Java UnsafeInput怎么用?Java UnsafeInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsafeInput类属于com.esotericsoftware.kryo.io包,在下文中一共展示了UnsafeInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: read
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public KryoMarker read(ObjectDataInput in)
throws IOException {
String className = in.readUTF();
int dataLength = in.readInt();
byte[] data = new byte[dataLength];
in.readFully(data);
try (Input input = new UnsafeInput(data)) {
Class<? extends KryoMarker> clazz = (Class<? extends KryoMarker>) Class.forName(className);
return getKryo().readObject(input, clazz);
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
}
示例2: testDeserializeJunkData
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
/**
* Junk tolerance test.
*
* <p>Verifies that the Serializer only throws KryoException or IndexOutOfBoundsException.
*
* <p>TODO(shahan): Allowing IndexOutOfBoundsException and NegativeArraySizeException here is not
* ideal, but Kryo itself encodes lengths in the stream and seeking to random lengths triggers
* this.
*/
void testDeserializeJunkData() {
Random rng = new Random(0);
int numFailures = 0;
for (int i = 0; i < DEFAULT_JUNK_INPUTS; ++i) {
byte[] junkData = new byte[rng.nextInt(JUNK_LENGTH_UPPER_BOUND)];
rng.nextBytes(junkData);
try {
UnsafeInput input = new UnsafeInput(junkData);
kryo.readObject(input, type);
// OK. Junk string was coincidentally parsed.
} catch (IndexOutOfBoundsException | NegativeArraySizeException | KryoException e) {
// OK. Deserialization of junk failed.
++numFailures;
}
}
assertThat(numFailures).isAtLeast(1);
}
示例3: testStrings
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
public void testStrings () throws IOException {
runStringTest(new UnsafeOutput(4096));
runStringTest(new UnsafeOutput(897));
runStringTest(new UnsafeOutput(new ByteArrayOutputStream()));
UnsafeOutput write = new UnsafeOutput(21);
String value = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";
write.writeString(value);
Input read = new UnsafeInput(write.toBytes());
assertEquals(value, read.readString());
runStringTest(127);
runStringTest(256);
runStringTest(1024 * 1023);
runStringTest(1024 * 1024);
runStringTest(1024 * 1025);
runStringTest(1024 * 1026);
runStringTest(1024 * 1024 * 2);
}
示例4: runCharTest
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private void runCharTest (UnsafeOutput write) throws IOException {
write.writeChar((char)0);
write.writeChar((char)63);
write.writeChar((char)64);
write.writeChar((char)127);
write.writeChar((char)128);
write.writeChar((char)8192);
write.writeChar((char)16384);
write.writeChar((char)32767);
write.writeChar((char)65535);
Input read = new UnsafeInput(write.toBytes());
assertEquals(0, read.readChar());
assertEquals(63, read.readChar());
assertEquals(64, read.readChar());
assertEquals(127, read.readChar());
assertEquals(128, read.readChar());
assertEquals(8192, read.readChar());
assertEquals(16384, read.readChar());
assertEquals(32767, read.readChar());
assertEquals(65535, read.readChar());
}
示例5: runVarIntTest
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private void runVarIntTest (UnsafeOutput write, ByteArrayOutputStream os) throws IOException {
write.writeVarInt(0, true);
write.writeVarInt(63, true);
write.writeVarInt(64, true);
write.writeVarInt(65535, true);
assertEquals(6, write.total());
write.flush();
assertEquals(6, os.size());
Input read = new UnsafeInput(os.toByteArray());
assertEquals(0, read.readVarInt(true));
assertEquals(63, read.readVarInt(true));
assertEquals(64, read.readVarInt(true));
assertEquals(65535, read.readVarInt(true));
assertEquals(true, read.eof());
}
示例6: unserialize
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T unserialize(byte[] data) {
Input in = new UnsafeInput(new ByteArrayInputStream(data));
T t = (T) kryo.readClassAndObject(in);
in.close();
return t;
}
示例7: bytesToObject
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public <T> T bytesToObject(byte[] bytes) {
if (bytes == null || bytes.length == 0) {
return null;
}
Input input = new UnsafeInput(bytes);
return (T) kryo.get().readClassAndObject(input);
}
示例8: runShortTest
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private void runShortTest (UnsafeOutput write) throws IOException {
write.writeShort(0);
write.writeShort(63);
write.writeShort(64);
write.writeShort(127);
write.writeShort(128);
write.writeShort(8192);
write.writeShort(16384);
write.writeShort(32767);
write.writeShort(-63);
write.writeShort(-64);
write.writeShort(-127);
write.writeShort(-128);
write.writeShort(-8192);
write.writeShort(-16384);
write.writeShort(-32768);
Input read = new UnsafeInput(write.toBytes());
assertEquals(0, read.readShort());
assertEquals(63, read.readShort());
assertEquals(64, read.readShort());
assertEquals(127, read.readShort());
assertEquals(128, read.readShort());
assertEquals(8192, read.readShort());
assertEquals(16384, read.readShort());
assertEquals(32767, read.readShort());
assertEquals(-63, read.readShort());
assertEquals(-64, read.readShort());
assertEquals(-127, read.readShort());
assertEquals(-128, read.readShort());
assertEquals(-8192, read.readShort());
assertEquals(-16384, read.readShort());
assertEquals(-32768, read.readShort());
}
示例9: runBooleanTest
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private void runBooleanTest (UnsafeOutput write) throws IOException {
for (int i = 0; i < 100; i++) {
write.writeBoolean(true);
write.writeBoolean(false);
}
Input read = new UnsafeInput(write.toBytes());
for (int i = 0; i < 100; i++) {
assertEquals(true, read.readBoolean());
assertEquals(false, read.readBoolean());
}
}
示例10: testSimpleVarInt
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
public void testSimpleVarInt() {
final int value = 39117;
final Output out = new UnsafeOutput(1024);
out.writeVarInt(value, true);
out.flush();
final Input in = new UnsafeInput(out.toBytes());
final int actualValue = in.readVarInt(true);
assertEquals(value, actualValue);
}
示例11: read
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public Object read(ObjectDataInput objectDataInput) throws IOException {
final Input input = new UnsafeInput((InputStream) objectDataInput);
final Kryo kryo = kryoThreadLocal.get();
return kryo.readClassAndObject(input);
}
示例12: valueToObject
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public <T> T valueToObject(byte[] data) {
Input input = new UnsafeInput(data);
input.read();
return (T) kryo.get().readClassAndObject(input);
}
示例13: getInput
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public Input getInput() {
return (isUnsafe)? new UnsafeInput() : new Input();
}
示例14: UnSafeKryoObjectInput
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
public UnSafeKryoObjectInput(InputStream inputStream){
input = new UnsafeInput(inputStream);
}
示例15: fromBytes
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private SubjectT fromBytes(byte[] bytes) {
return kryo.readObject(new UnsafeInput(bytes), type);
}