public void checkVarDelimitedBoundry(int initialGap, int secondWriteSize) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int bufferSize = BUF_SIZE;
    final LinkedBuffer lb = new LinkedBuffer(bufferSize);
    WriteSession session = new WriteSession(lb, bufferSize);

    // Should fill up the buffer with initialGap byte(s) left
    StreamedStringSerializer.writeUTF8(repeatChar('a', bufferSize - initialGap), session, out, lb);

    // Write a string of length secondWriteSize that should be larger
    // than the next buffer size
    assertTrue(secondWriteSize > bufferSize);
    StreamedStringSerializer.writeUTF8VarDelimited(
        repeatChar('a', secondWriteSize), session, out, lb);
  }
  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);
    }
  }
  static void checkVarDelimited(String str, int size, int stringLen) throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb);
    StreamedStringSerializer.writeUTF8VarDelimited(str, session, out, lb);
    LinkedBuffer.writeTo(out, lb);

    byte[] buf = out.toByteArray();

    assertTrue(buf.length == stringLen + size);

    int len = readRawVarint32(buf, 0);
    assertTrue(len == stringLen);

    print("total len: " + buf.length);
  }
  static void checkFixedDelimited(String str) throws Exception {
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    DataOutputStream dout = new DataOutputStream(bout);
    dout.writeUTF(str);
    dout.close();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb);
    StreamedStringSerializer.writeUTF8FixedDelimited(str, session, out, lb);
    LinkedBuffer.writeTo(out, lb);

    byte[] b1 = bout.toByteArray();

    byte[] b2 = out.toByteArray();

    assertEquals(b1, b2);
  }
  static void check(String str) throws Exception {
    byte[] builtin = BUILT_IN_SERIALIZER.serialize(str);

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    LinkedBuffer lb = new LinkedBuffer(BUF_SIZE);
    WriteSession session = new WriteSession(lb);

    StreamedStringSerializer.writeUTF8(str, session, out, lb);
    LinkedBuffer.writeTo(out, lb);

    assertTrue(builtin.length == session.size);

    byte[] buffered = out.toByteArray();

    assertTrue(builtin.length == buffered.length);

    String strBuiltin = new String(builtin, "UTF-8");
    String strBuffered = new String(buffered, "UTF-8");

    assertEquals(strBuiltin, strBuffered);
    print(strBuiltin);
    print("len: " + builtin.length);
  }