code: private void checkWrite(int size) {
      // If the buffer does not have enough bytes remaining, attempt to discard some of the read bytes.
      // It is possible that the buffer could discard 0 bytes, so we ensure the buffer is writable after
      // discarding some read bytes, and if not discard all read bytes.
      if (buffer.writerIndex() + size > buffer.maxCapacity()) {
        buffer.discardSomeReadBytes();
        if (buffer.writerIndex() + size > buffer.maxCapacity()) {
          buffer.discardReadBytes();
        }
      }
    }
docs: Ensures that {@code size} bytes can be written to the buffer.