public void finish() throws IOException {
    if (finished) {
      return;
    }
    flush();
    // Finish the stream with the terminatorValue.
    VarInt.encode(terminatorValue, os);
    if (!BUFFER_POOL.offer(buffer)) {
      // The pool is full, we can't store the buffer. We just drop the buffer.
    }
    finished = true;
  }
@Test
  public void testBehaviorWhenBufferPoolEmpty() throws Exception {
    BUFFER_POOL.clear();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    BufferedElementCountingOutputStream os = createAndWriteValues(toBytes("abcdefghij"), baos);
    assertEquals(0, BUFFER_POOL.size());
    os.finish();
    assertEquals(1, BUFFER_POOL.size());
  }