Пример #1
0
  @Test
  public void testRead4PrefixedString_Null() throws Exception {
    byte[] length = Ints.toByteArray(-1);

    Buffer buffer = new FixedBuffer(length);
    String prefixedString = buffer.read4PrefixedString();
    Assert.assertEquals(prefixedString, null);
  }
Пример #2
0
  @Test
  public void testRead4PrefixedString() throws Exception {
    String value = "test";
    byte[] length = Ints.toByteArray(value.length());
    byte[] string = value.getBytes();
    byte[] result = BytesUtils.merge(length, string);

    Buffer buffer = new FixedBuffer(result);
    String prefixedString = buffer.read4PrefixedString();
    Assert.assertEquals(prefixedString, value);
  }
Пример #3
0
  private void checkPut4PrefixedBytes(String test, int expected) {
    Buffer buffer = new FixedBuffer(1024);
    if (test != null) {
      buffer.put4PrefixedBytes(test.getBytes(UTF8_CHARSET));
    } else {
      buffer.put4PrefixedBytes(null);
    }

    buffer.put(expected);
    byte[] buffer1 = buffer.getBuffer();

    Buffer actual = new FixedBuffer(buffer1);
    String s = actual.read4PrefixedString();
    Assert.assertEquals(test, s);

    int i = actual.readInt();
    Assert.assertEquals(expected, i);
  }