code: private int write1(byte b[], int off, int len) throws IOException {
      eventStartWrite();
  
      try {
        if(count==0 && bytesSentInChunk + len>=buf.length) {
          // local buffer is empty and user data can fill the current chunk
          // checksum and output data
          final int length = buf.length - bytesSentInChunk;
          sum.update(b, off, length);
          writeChecksumChunk(b, off, length, false);
          // start a new chunk
          bytesSentInChunk = 0;
          return length;
        }
      
        // copy user data to local buffer
        int bytesToCopy = buf.length - bytesSentInChunk - count;
        bytesToCopy = (len<bytesToCopy) ? len : bytesToCopy;
        sum.update(b, off, bytesToCopy);
        System.arraycopy(b, off, buf, count, bytesToCopy);
        count += bytesToCopy;
        if (count + bytesSentInChunk == buf.length) {
          // local buffer is full
          flushBuffer(true, shouldKeepPartialChunkData());
        } 
        return bytesToCopy;
      } finally {
        eventEndWrite();
      }
    }
docs: Write a portion of an array, flushing to the underlying
  stream at most once if necessary.