code: @Override
    public synchronized void write(byte[] source, int offset, int len) throws IOException {
  
      COSDataBlocks.validateWriteArgs(source, offset, len);
      checkOpen();
      if (len == 0) {
        return;
      }
      COSDataBlocks.DataBlock block = createBlockIfNeeded();
      int written = block.write(source, offset, len);
      int remainingCapacity = block.remainingCapacity();
      if (written < len) {
        // not everything was written, the block has run out
        // of capacity
        // Trigger an upload then process the remainder.
        LOG.debug("writing more data than block has capacity -triggering upload");
        uploadCurrentBlock();
        // tail recursion is mildly expensive, but given buffer sizes must be MB.
        // it's unlikely to recurse very deeply.
        write(source, offset + written, len - written);
      } else {
        if (remainingCapacity == 0) {
          // the whole buffer is done, trigger an upload
          uploadCurrentBlock();
        }
      }
    }
docs: Writes a range of bytes from to the memory buffer. If this causes the
  buffer to reach its limit, the actual upload is submitted to the threadpool
  and the remainder of the array is written to memory (recursively).
  
  @param source byte array containing
  @param offset offset in array where to start
  @param len number of bytes to be written
  @throws IOException on any problem