Package com.esotericsoftware.kryo.io

Examples of com.esotericsoftware.kryo.io.UnsafeMemoryInput


    final public void read (Input input, Object object) {
      if (bulkReadsSupported && input instanceof UnsafeInput) {
        UnsafeInput unsafeInput = (UnsafeInput)input;
        unsafeInput.readBytes(object, offset, len);
      } else if (bulkReadsSupported && input instanceof UnsafeMemoryInput) {
        UnsafeMemoryInput unsafeInput = (UnsafeMemoryInput)input;
        unsafeInput.readBytes(object, offset, len);
      } else {
        readSlow(input, object);
      }
    }
View Full Code Here


  }

  public void testCanReadInt () throws IOException {
    UnsafeMemoryOutput write = new UnsafeMemoryOutput(new ByteArrayOutputStream());

    Input read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(false, read.canReadInt());

    write.writeVarInt(400, true);

    read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(true, read.canReadInt());
    read.setLimit(read.limit() - 1);
    assertEquals(false, read.canReadInt());
  }
View Full Code Here

    assertEquals(4, write.writeInt(-134217728, false));
    assertEquals(4, write.writeInt(-134217728, true));
    assertEquals(4, write.writeInt(-134217729, false));
    assertEquals(4, write.writeInt(-134217729, true));

    Input read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(0, read.readInt());
    assertEquals(63, read.readInt());
    assertEquals(64, read.readInt());
    assertEquals(127, read.readInt());
    assertEquals(128, read.readInt());
    assertEquals(8192, read.readInt());
    assertEquals(16384, read.readInt());
    assertEquals(2097151, read.readInt());
    assertEquals(1048575, read.readInt());
    assertEquals(134217727, read.readInt());
    assertEquals(268435455, read.readInt());
    assertEquals(134217728, read.readInt());
    assertEquals(268435456, read.readInt());
    assertEquals(-2097151, read.readInt());
    assertEquals(-1048575, read.readInt());
    assertEquals(-134217727, read.readInt());
    assertEquals(-268435455, read.readInt());
    assertEquals(-134217728, read.readInt());
    assertEquals(-268435456, read.readInt());
    assertEquals(true, read.canReadInt());
    assertEquals(true, read.canReadInt());
    assertEquals(true, read.canReadInt());
    assertEquals(0, read.readInt(true));
    assertEquals(0, read.readInt(false));
    assertEquals(63, read.readInt(true));
    assertEquals(63, read.readInt(false));
    assertEquals(64, read.readInt(true));
    assertEquals(64, read.readInt(false));
    assertEquals(127, read.readInt(true));
    assertEquals(127, read.readInt(false));
    assertEquals(128, read.readInt(true));
    assertEquals(128, read.readInt(false));
    assertEquals(8191, read.readInt(true));
    assertEquals(8191, read.readInt(false));
    assertEquals(8192, read.readInt(true));
    assertEquals(8192, read.readInt(false));
    assertEquals(16383, read.readInt(true));
    assertEquals(16383, read.readInt(false));
    assertEquals(16384, read.readInt(true));
    assertEquals(16384, read.readInt(false));
    assertEquals(2097151, read.readInt(true));
    assertEquals(2097151, read.readInt(false));
    assertEquals(1048575, read.readInt(true));
    assertEquals(1048575, read.readInt(false));
    assertEquals(134217727, read.readInt(true));
    assertEquals(134217727, read.readInt(false));
    assertEquals(268435455, read.readInt(true));
    assertEquals(268435455, read.readInt(false));
    assertEquals(134217728, read.readInt(true));
    assertEquals(134217728, read.readInt(false));
    assertEquals(268435456, read.readInt(true));
    assertEquals(268435456, read.readInt(false));
    assertEquals(-64, read.readInt(false));
    assertEquals(-64, read.readInt(true));
    assertEquals(-65, read.readInt(false));
    assertEquals(-65, read.readInt(true));
    assertEquals(-8192, read.readInt(false));
    assertEquals(-8192, read.readInt(true));
    assertEquals(-1048576, read.readInt(false));
    assertEquals(-1048576, read.readInt(true));
    assertEquals(-134217728, read.readInt(false));
    assertEquals(-134217728, read.readInt(true));
    assertEquals(-134217729, read.readInt(false));
    assertEquals(-134217729, read.readInt(true));
    assertEquals(false, read.canReadInt());

    Random random = new Random();
    for (int i = 0; i < 10000; i++) {
      int value = random.nextInt();
      write.clear();
      write.writeInt(value);
      write.writeInt(value, true);
      write.writeInt(value, false);
      read.setBuffer(write.toBytes());
      assertEquals(value, read.readInt());
      assertEquals(value, read.readInt(true));
      assertEquals(value, read.readInt(false));
    }
  }
View Full Code Here

      outputBuffer.release();
      outputBuffer = new UnsafeMemoryOutput(bufAddress, 4096);
      outputBuffer.writeInt(10);

      inputBuffer = new UnsafeMemoryInput(outputBuffer.getByteBuffer());
      inputBuffer.readInt();
      inputBuffer.release();
      outputBuffer.release();
    } catch (Throwable t) {
      System.err.println("Streams with preallocated direct memory are not supported on this JVM");
View Full Code Here

    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};
    ByteArrayInputStream buffer = new ByteArrayInputStream(bytes);
    Input input = new UnsafeMemoryInput(buffer, 2);
    byte[] temp = new byte[1024];
    int count = input.read(temp, 512, bytes.length);
    assertEquals(bytes.length, count);
    byte[] temp2 = new byte[count];
    System.arraycopy(temp, 512, temp2, 0, count);
    assertEquals(bytes, temp2);

    input = new UnsafeMemoryInput(bytes);
    count = input.read(temp, 512, 512);
    assertEquals(bytes.length, count);
    temp2 = new byte[count];
    System.arraycopy(temp, 512, temp2, 0, count);
    assertEquals(bytes, temp2);
  }
View Full Code Here

    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);
 
View Full Code Here

      buffer.append((char)i);

    String value = buffer.toString();
    write.writeString(value);
    write.writeString(value);
    Input read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(value, read.readString());
    assertEquals(value, read.readStringBuilder().toString());

    write.clear();
    write.writeString(buffer);
    write.writeString(buffer);
    read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(value, read.readStringBuilder().toString());
    assertEquals(value, read.readString());

    if (length <= 127) {
      write.clear();
      write.writeAscii(value);
      write.writeAscii(value);
      read = new UnsafeMemoryInput(write.toBytes());
      assertEquals(value, read.readStringBuilder().toString());
      assertEquals(value, read.readString());
    }
  }
View Full Code Here

    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());
  }
View Full Code Here

    assertEquals(8, write.writeLong(-134217728, false));
    assertEquals(8, write.writeLong(-134217728, true));
    assertEquals(8, write.writeLong(-134217729, false));
    assertEquals(8, write.writeLong(-134217729, true));

    Input read = new UnsafeMemoryInput(write.toBytes());
    assertEquals(0, read.readLong());
    assertEquals(63, read.readLong());
    assertEquals(64, read.readLong());
    assertEquals(127, read.readLong());
    assertEquals(128, read.readLong());
    assertEquals(8192, read.readLong());
    assertEquals(16384, read.readLong());
    assertEquals(2097151, read.readLong());
    assertEquals(1048575, read.readLong());
    assertEquals(134217727, read.readLong());
    assertEquals(268435455, read.readLong());
    assertEquals(134217728, read.readLong());
    assertEquals(268435456, read.readLong());
    assertEquals(-2097151, read.readLong());
    assertEquals(-1048575, read.readLong());
    assertEquals(-134217727, read.readLong());
    assertEquals(-268435455, read.readLong());
    assertEquals(-134217728, read.readLong());
    assertEquals(-268435456, read.readLong());
    assertEquals(0, read.readLong(true));
    assertEquals(0, read.readLong(false));
    assertEquals(63, read.readLong(true));
    assertEquals(63, read.readLong(false));
    assertEquals(64, read.readLong(true));
    assertEquals(64, read.readLong(false));
    assertEquals(127, read.readLong(true));
    assertEquals(127, read.readLong(false));
    assertEquals(128, read.readLong(true));
    assertEquals(128, read.readLong(false));
    assertEquals(8191, read.readLong(true));
    assertEquals(8191, read.readLong(false));
    assertEquals(8192, read.readLong(true));
    assertEquals(8192, read.readLong(false));
    assertEquals(16383, read.readLong(true));
    assertEquals(16383, read.readLong(false));
    assertEquals(16384, read.readLong(true));
    assertEquals(16384, read.readLong(false));
    assertEquals(2097151, read.readLong(true));
    assertEquals(2097151, read.readLong(false));
    assertEquals(1048575, read.readLong(true));
    assertEquals(1048575, read.readLong(false));
    assertEquals(134217727, read.readLong(true));
    assertEquals(134217727, read.readLong(false));
    assertEquals(268435455, read.readLong(true));
    assertEquals(268435455, read.readLong(false));
    assertEquals(134217728, read.readLong(true));
    assertEquals(134217728, read.readLong(false));
    assertEquals(268435456, read.readLong(true));
    assertEquals(268435456, read.readLong(false));
    assertEquals(-64, read.readLong(false));
    assertEquals(-64, read.readLong(true));
    assertEquals(-65, read.readLong(false));
    assertEquals(-65, read.readLong(true));
    assertEquals(-8192, read.readLong(false));
    assertEquals(-8192, read.readLong(true));
    assertEquals(-1048576, read.readLong(false));
    assertEquals(-1048576, read.readLong(true));
    assertEquals(-134217728, read.readLong(false));
    assertEquals(-134217728, read.readLong(true));
    assertEquals(-134217729, read.readLong(false));
    assertEquals(-134217729, read.readLong(true));

    Random random = new Random();
    for (int i = 0; i < 10000; i++) {
      long value = random.nextLong();
      write.clear();
      write.writeLong(value);
      write.writeLong(value, true);
      write.writeLong(value, false);
      read.setBuffer(write.toBytes());
      assertEquals("Element " + i, value, read.readLong());
      assertEquals("Element " + i, value, read.readLong(true));
      assertEquals("Element " + i, value, read.readLong(false));
    }
  }
View Full Code Here

    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());
  }
View Full Code Here

TOP

Related Classes of com.esotericsoftware.kryo.io.UnsafeMemoryInput

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.