本文整理汇总了Java中com.esotericsoftware.kryo.io.UnsafeOutput类的典型用法代码示例。如果您正苦于以下问题:Java UnsafeOutput类的具体用法?Java UnsafeOutput怎么用?Java UnsafeOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnsafeOutput类属于com.esotericsoftware.kryo.io包,在下文中一共展示了UnsafeOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWriteBytes
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
public void testWriteBytes () throws IOException {
UnsafeOutput buffer = new UnsafeOutput(512);
buffer.writeBytes(new byte[] {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26});
buffer.writeBytes(new byte[] {31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46});
buffer.writeByte(51);
buffer.writeBytes(new byte[] {52, 53, 54, 55, 56, 57, 58});
buffer.writeByte(61);
buffer.writeByte(62);
buffer.writeByte(63);
buffer.writeByte(64);
buffer.writeByte(65);
buffer.flush();
assertEquals(new byte[] { //
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, //
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, //
51, 52, 53, 54, 55, 56, 57, 58, //
61, 62, 63, 64, 65}, buffer.toBytes());
}
示例2: testStrings
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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);
}
示例3: runCharTest
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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());
}
示例4: runVarIntTest
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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());
}
示例5: serialize
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public byte[] serialize(T packet) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Output out = new UnsafeOutput(baos);
kryo.writeClassAndObject(out, packet);
out.close();
return baos.toByteArray();
}
示例6: write
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public void write(ObjectDataOutput objectDataOutput, Object object)
throws IOException {
final Output output = new UnsafeOutput((OutputStream) objectDataOutput);
final Kryo kryo = kryoThreadLocal.get();
kryo.writeClassAndObject(output, object);
output.flush();
}
示例7: objectToBytes
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public byte[] objectToBytes(Object value) {
Output output = new UnsafeOutput(2000, -1);
output.writeByte(MARKER_KRYO);
kryo.get().writeClassAndObject(output, value);
return output.toBytes();
}
示例8: objectToBytes
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public byte[] objectToBytes(Object object) {
if (object == null) {
return EMPTY;
}
Output output = new UnsafeOutput(2000, -1);
kryo.get().writeClassAndObject(output, object);
return output.toBytes();
}
示例9: write
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public void write(ObjectDataOutput out, KryoMarker object)
throws IOException {
String className;
byte[] data;
if (object instanceof KryoEnvelope) {
KryoEnvelope envelope = (KryoEnvelope) object;
className = envelope.getClassName();
data = envelope.getData();
} else {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); //
Output output = new UnsafeOutput(baos);) {
className = object.getClass().getName();
getKryo().writeObject(output, object);
output.flush();
data = baos.toByteArray();
}
}
out.writeUTF(className);
out.writeInt(data.length);
out.write(data);
}
示例10: toBytes
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
private byte[] toBytes(SubjectT subject) {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
UnsafeOutput out = new UnsafeOutput(byteOut);
kryo.writeObject(out, subject);
out.flush();
return byteOut.toByteArray();
}
示例11: testOutputStream
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
public void testOutputStream () throws IOException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
UnsafeOutput output = new UnsafeOutput(buffer, 2);
output.writeBytes(new byte[] {11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26});
output.writeBytes(new byte[] {31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46});
output.writeBytes(new byte[] {51, 52, 53, 54, 55, 56, 57, 58});
output.writeBytes(new byte[] {61, 62, 63, 64, 65});
output.flush();
assertEquals(new byte[] { //
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, //
31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, //
51, 52, 53, 54, 55, 56, 57, 58, //
61, 62, 63, 64, 65}, buffer.toByteArray());
}
示例12: runShortTest
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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());
}
示例13: runBooleanTest
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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());
}
}
示例14: testSimpleVarInt
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的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);
}
示例15: getOutput
import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public Output getOutput() {
return (isUnsafe)? new UnsafeOutput() : new Output();
}