本文整理汇总了Java中com.esotericsoftware.kryo.io.UnsafeInput类的典型用法代码示例。如果您正苦于以下问题:Java UnsafeInput类的具体用法?Java UnsafeInput怎么用?Java UnsafeInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsafeInput类属于com.esotericsoftware.kryo.io包,在下文中一共展示了UnsafeInput类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:noctarius,项目名称:hazelcast-unaware-serialization,代码行数:18,代码来源:KryoAvailableSerializer.java
示例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);
}
开发者ID:bazelbuild,项目名称:bazel,代码行数:27,代码来源:SerializerTester.java
示例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);
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:20,代码来源:UnsafeInputOutputTest.java
示例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());
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:23,代码来源:UnsafeInputOutputTest.java
示例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());
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:17,代码来源:UnsafeInputOutputTest.java
示例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;
}
开发者ID:BRjDevs,项目名称:BRjLibs,代码行数:9,代码来源:KryoUnsafePacketFactory.java
示例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);
}
开发者ID:visallo,项目名称:vertexium,代码行数:9,代码来源:KryoVertexiumSerializer.java
示例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());
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:35,代码来源:UnsafeInputOutputTest.java
示例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());
}
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:13,代码来源:UnsafeInputOutputTest.java
示例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);
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:10,代码来源:UnsafeInputOutputTest.java
示例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);
}
开发者ID:x10-lang,项目名称:apgas,代码行数:7,代码来源:KryoSerializer.java
示例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);
}
开发者ID:visallo,项目名称:vertexium,代码行数:7,代码来源:KryoQuickTypeSerializer.java
示例13: getInput
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
public Input getInput() {
return (isUnsafe)? new UnsafeInput() : new Input();
}
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:5,代码来源:FastestStreamFactory.java
示例14: UnSafeKryoObjectInput
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
public UnSafeKryoObjectInput(InputStream inputStream){
input = new UnsafeInput(inputStream);
}
开发者ID:AllenRay,项目名称:dubbo-ex,代码行数:4,代码来源:UnSafeKryoObjectInput.java
示例15: fromBytes
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
private SubjectT fromBytes(byte[] bytes) {
return kryo.readObject(new UnsafeInput(bytes), type);
}
开发者ID:bazelbuild,项目名称:bazel,代码行数:4,代码来源:SerializerTester.java
示例16: streamedRead
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
@Override
protected T streamedRead(InputStream inputStream) throws IOException {
return get().readObject(new UnsafeInput(inputStream), getType());
}
开发者ID:lburgazzoli,项目名称:lb-hazelcast,代码行数:5,代码来源:KryoSerializer.java
示例17: runStringTest
import com.esotericsoftware.kryo.io.UnsafeInput; //导入依赖的package包/类
public void runStringTest (UnsafeOutput write) throws IOException {
String value1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ\rabcdefghijklmnopqrstuvwxyz\n1234567890\t\"!`?'.,;:()[]{}<>|/@\\^$-%+=#_&~*";
String value2 = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";
write.writeString("");
write.writeString("1");
write.writeString("22");
write.writeString("uno");
write.writeString("dos");
write.writeString("tres");
write.writeString(null);
write.writeString(value1);
write.writeString(value2);
for (int i = 0; i < 127; i++)
write.writeString(String.valueOf((char)i));
for (int i = 0; i < 127; i++)
write.writeString(String.valueOf((char)i) + "abc");
Input read = new UnsafeInput(write.toBytes());
assertEquals("", read.readString());
assertEquals("1", read.readString());
assertEquals("22", read.readString());
assertEquals("uno", read.readString());
assertEquals("dos", read.readString());
assertEquals("tres", read.readString());
assertEquals(null, read.readString());
assertEquals(value1, read.readString());
assertEquals(value2, read.readString());
for (int i = 0; i < 127; i++)
assertEquals(String.valueOf((char)i), read.readString());
for (int i = 0; i < 127; i++)
assertEquals(String.valueOf((char)i) + "abc", read.readString());
read.rewind();
assertEquals("", read.readStringBuilder().toString());
assertEquals("1", read.readStringBuilder().toString());
assertEquals("22", read.readStringBuilder().toString());
assertEquals("uno", read.readStringBuilder().toString());
assertEquals("dos", read.readStringBuilder().toString());
assertEquals("tres", read.readStringBuilder().toString());
assertEquals(null, read.readStringBuilder());
assertEquals(value1, read.readStringBuilder().toString());
assertEquals(value2, read.readStringBuilder().toString());
for (int i = 0; i < 127; i++)
assertEquals(String.valueOf((char)i), read.readStringBuilder().toString());
for (int i = 0; i < 127; i++)
assertEquals(String.valueOf((char)i) + "abc", read.readStringBuilder().toString());
}
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:49,代码来源:UnsafeInputOutputTest.java
注:本文中的com.esotericsoftware.kryo.io.UnsafeInput类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论