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)); }
public void testInt() throws Exception { for (int i : int_targets) { ByteArrayOutputStream out = new ByteArrayOutputStream(); LinkedBuffer lb = new LinkedBuffer(BUF_SIZE); WriteSession session = new WriteSession(lb); StreamedStringSerializer.writeInt(i, session, out, lb); LinkedBuffer.writeTo(out, lb); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE); WriteSession session2 = new WriteSession(lb2); StreamedStringSerializer.writeInt(i, session2, out2, lb2); LinkedBuffer.writeTo(out2, lb2); byte[] buffered = out.toByteArray(); byte[] buffered_needed_to_flush = out2.toByteArray(); byte[] builtin = STRING.ser(Integer.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_flush); } }