code: private void refreshBuffer() throws IOException {
      if (output == null) {
        // We're writing to a single buffer.
        throw new OutOfSpaceException();
      }
  
      // Since we have an output stream, this is our buffer
      // and buffer offset == 0
      output.write(buffer, 0, position);
      position = 0;
    }
docs: Internal helper that writes the current buffer to the output. The
  buffer position is reset to its initial value when this returns.