コード例 #1
0
  public void testMultipleLargeStringsExceedingBufferSizeDelimited() throws Exception {
    LinkedBuffer buffer = LinkedBuffer.allocate(256);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    WriteSession session = new WriteSession(buffer, out);
    String utf8OneByte = repeatChar('a', 1024);
    String utf8TwoBytes = repeatChar((char) 0x7ff, 1024 / 2);
    String utf8ThreeBytes = repeatChar((char) 0x800, 1024 / 3);

    writeToSession(utf8OneByte, utf8TwoBytes, utf8ThreeBytes, session, true);
    assertTrue(session.tail == session.head);
    // temporary buffers will remain
    assertTrue(session.tail.next != null);
    // flush remaining
    LinkedBuffer.writeTo(out, buffer);
    // clear
    buffer.clear();

    byte[] data = out.toByteArray();

    LinkedBuffer buffer2 = LinkedBuffer.allocate(256);
    WriteSession session2 = new WriteSession(buffer2);

    writeToSession(utf8OneByte, utf8TwoBytes, utf8ThreeBytes, session2, true);

    byte[] data2 = session2.toByteArray();

    assertEquals(STRING.deser(data), STRING.deser(data2));
  }