public int writeUTF8(final CharSequence chars,int off,int len){
  if (len > remaining()) {
    return writeUTF8Slow(chars,off,len);
  }
  final Block block=current;
  int limit=block.limit;
  char ch='\0';
  int octets=0;
  while (len > 0) {
    ch=chars.charAt(off);
    if (ch >= UTF8_2_OCTET_MIN_VALUE) {
      break;
    }
    block.data[limit++]=(byte)ch;
    octets++;
    off++;
    len--;
  }
  block.limit=limit;
  if (len > 0) {
    if (ch < UTF8_3_OCTET_MIN_VALUE) {
      return octets + writeUTF8UpTo2Byte(chars,off,len);
    }
    if (ch >= LOW_SURROGATE_FIRST && ch <= LOW_SURROGATE_LAST) {
      throw new IllegalArgumentException("Unpaired low surrogate: " + ch);
    }
    if (ch >= HIGH_SURROGATE_FIRST && ch <= HIGH_SURROGATE_LAST) {
      return octets + writeUTF8Slow(chars,off,len);
    }
    return octets + writeUTF8UpTo3Byte(chars,off,len);
  }
  return octets;
}

public int writeUTF8 ( final CharSequence chars , int off , int len ) { if ( len > remaining ( ) ) { return writeUTF8Slow ( chars , off , len ) ; } final Block block = current ; int limit = block . limit ; char ch = '\0' ; int octets = 0 ; while ( len > 0 ) { ch = chars . charAt ( off ) ; if ( ch >= UTF8_2_OCTET_MIN_VALUE ) { break ; } block . data [ limit ++ ] = ( byte ) ch ; octets ++ ; off ++ ; len -- ; } block . limit = limit ; if ( len > 0 ) { if ( ch < UTF8_3_OCTET_MIN_VALUE ) { return octets + writeUTF8UpTo2Byte ( chars , off , len ) ; } if ( ch >= LOW_SURROGATE_FIRST && ch <= LOW_SURROGATE_LAST ) { throw new IllegalArgumentException ( "Unpaired low surrogate: " + ch ) ; } if ( ch >= HIGH_SURROGATE_FIRST && ch <= HIGH_SURROGATE_LAST ) { return octets + writeUTF8Slow ( chars , off , len ) ; } return octets + writeUTF8UpTo3Byte ( chars , off , len ) ; } return octets ; }
returns the number of octets written .
