public void write(byte[] arr, int off, int len) throws IOException {
    if (len > buf.length - pos) {
      if (buf.length != getMaxPacketLength()) {
        growBuffer(len);
      }

      //max buffer size
      if (len > buf.length - pos) {

        if (mark != -1) {
          growBuffer(len);
          if (mark != -1) {
            flushBufferStopAtMark();
          }

        } else {
          //not enough space in buffer, will stream :
          // fill buffer and flush until all data are snd
          int remainingLen = len;
          do {
            int lenToFillBuffer = Math.min(getMaxPacketLength() - pos, remainingLen);
            System.arraycopy(arr, off, buf, pos, lenToFillBuffer);
            remainingLen -= lenToFillBuffer;
            off += lenToFillBuffer;
            pos += lenToFillBuffer;
            if (remainingLen > 0) {
              flushBuffer(false);
            } else {
              break;
            }
          } while (true);
          return;
        }
      }
    }

    System.arraycopy(arr, off, buf, pos, len);
    pos += len;
  }
public void write ( byte [ ] arr , int off , int len ) throws IOException { if ( len > buf . length - pos ) { if ( buf . length != getMaxPacketLength ( ) ) { growBuffer ( len ) ; } if ( len > buf . length - pos ) { if ( mark != - 1 ) { growBuffer ( len ) ; if ( mark != - 1 ) { flushBufferStopAtMark ( ) ; } } else { int remainingLen = len ; do { int lenToFillBuffer = Math . min ( getMaxPacketLength ( ) - pos , remainingLen ) ; System . arraycopy ( arr , off , buf , pos , lenToFillBuffer ) ; remainingLen -= lenToFillBuffer ; off += lenToFillBuffer ; pos += lenToFillBuffer ; if ( remainingLen > 0 ) { flushBuffer ( false ) ; } else { break ; } } while ( true ) ; return ; } } } System . arraycopy ( arr , off , buf , pos , len ) ; pos += len ; }
Write byte array to buffer. If buffer is full, flush socket.

@param arr byte array
@param off offset
@param len byte length to write
@throws IOException if socket error occur