Java 类com.esotericsoftware.kryo.io.UnsafeMemoryOutput 实例源码

项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testWriteBytes () throws IOException {
    UnsafeMemoryOutput buffer = new UnsafeMemoryOutput(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());
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testStrings () throws IOException {
    runStringTest(new UnsafeMemoryOutput(4096));
    runStringTest(new UnsafeMemoryOutput(897));
    runStringTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));

    UnsafeMemoryOutput write = new UnsafeMemoryOutput(21);
    String value = "abcdef\u00E1\u00E9\u00ED\u00F3\u00FA\u1234";
    write.writeString(value);
    Input read = new UnsafeMemoryInput(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);
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
private void runCharTest (UnsafeMemoryOutput 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 UnsafeMemoryInput(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());
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testOutputStream () throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UnsafeMemoryOutput output = new UnsafeMemoryOutput(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());
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
private void runShortTest (UnsafeMemoryOutput 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 UnsafeMemoryInput(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());
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
private void runBooleanTest (UnsafeMemoryOutput write) throws IOException {
    for (int i = 0; i < 100; i++) {
        write.writeBoolean(true);
        write.writeBoolean(false);
    }

    Input read = new UnsafeMemoryInput(write.toBytes());
    for (int i = 0; i < 100; i++) {
        assertEquals(true, read.readBoolean());
        assertEquals(false, read.readBoolean());
    }
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void runStringTest (UnsafeMemoryOutput 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 UnsafeMemoryInput(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());
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testInts () throws IOException {
    runIntTest(new UnsafeMemoryOutput(4096));
    runIntTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testLongs () throws IOException {
    runLongTest(new UnsafeMemoryOutput(4096));
    runLongTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testShorts () throws IOException {
    runShortTest(new UnsafeMemoryOutput(4096));
    runShortTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testFloats () throws IOException {
    runFloatTest(new UnsafeMemoryOutput(4096));
    runFloatTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testDoubles () throws IOException {
    runDoubleTest(new UnsafeMemoryOutput(4096));
    runDoubleTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testBooleans () throws IOException {
    runBooleanTest(new UnsafeMemoryOutput(4096));
    runBooleanTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}
项目:kryo-mavenized    文件:UnsafeMemoryInputOutputTest.java   
public void testChars () throws IOException {
    runCharTest(new UnsafeMemoryOutput(4096));
    runCharTest(new UnsafeMemoryOutput(new ByteArrayOutputStream()));
}