当前位置: 首页>>代码示例>>Java>>正文


Java UnsafeOutput类代码示例

本文整理汇总了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());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:20,代码来源:UnsafeInputOutputTest.java

示例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);
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:20,代码来源:UnsafeInputOutputTest.java

示例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());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:23,代码来源:UnsafeInputOutputTest.java

示例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());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:17,代码来源:UnsafeInputOutputTest.java

示例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();
}
 
开发者ID:BRjDevs,项目名称:BRjLibs,代码行数:9,代码来源:KryoUnsafePacketFactory.java

示例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();
}
 
开发者ID:x10-lang,项目名称:apgas,代码行数:9,代码来源:KryoSerializer.java

示例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();
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:8,代码来源:KryoQuickTypeSerializer.java

示例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();
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:10,代码来源:KryoVertexiumSerializer.java

示例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);
}
 
开发者ID:noctarius,项目名称:hazelcast-unaware-serialization,代码行数:28,代码来源:KryoAvailableSerializer.java

示例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();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:8,代码来源:SerializerTester.java

示例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());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:16,代码来源:UnsafeInputOutputTest.java

示例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());
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:35,代码来源:UnsafeInputOutputTest.java

示例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());
	}
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:13,代码来源:UnsafeInputOutputTest.java

示例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);
}
 
开发者ID:esialb,项目名称:kryo-mavenized,代码行数:10,代码来源:UnsafeInputOutputTest.java

示例15: getOutput

import com.esotericsoftware.kryo.io.UnsafeOutput; //导入依赖的package包/类
@Override
public Output getOutput() {
	return (isUnsafe)? new UnsafeOutput() : new Output();
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:5,代码来源:FastestStreamFactory.java


注:本文中的com.esotericsoftware.kryo.io.UnsafeOutput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。