class BufferedElementCountingOutputStream extends OutputStream {

  public void finish() throws IOException {
    if (finished) {
      return;
    }
    flush();
    // Finish the stream by stating that there are 0 elements that follow.
    VarInt.encode(0, os);
    if (!BUFFER_POOL.offer(buffer)) {
      // The pool is full, we can't store the buffer. We just drop the buffer.
    }
    finished = true;
  }

  public  BufferedElementCountingOutputStream(OutputStream os);
    BufferedElementCountingOutputStream(OutputStream os, int bufferSize);

}