protected int read(InputStream inputStream,byte[] buffer,char[] divider) throws IOException {
  int index=0;
  int dividerIndex=0;
  do {
    byte readByte=(byte)(0x000000FF & inputStream.read());
    if (readByte == -1) {
      return index;
    }
    if (readByte == divider[dividerIndex]) {
      dividerIndex++;
    }
    if (dividerIndex == divider.length) {
      index-=dividerIndex - 1;
      for (int i=index; i < index + dividerIndex; i++) {
        if (i >= buffer.length) {
          break;
        }
        buffer[i]=0;
      }
      return index;
    }
    buffer[index]=readByte;
    index++;
  }
 while (index < buffer.length);
  return index;
}

protected int read ( InputStream inputStream , byte [ ] buffer , char [ ] divider ) throws IOException { int index = 0 ; int dividerIndex = 0 ; do { byte readByte = ( byte ) ( 0x000000FF & inputStream . read ( ) ) ; if ( readByte == - 1 ) { return index ; } if ( readByte == divider [ dividerIndex ] ) { dividerIndex ++ ; } if ( dividerIndex == divider . length ) { index -= dividerIndex - 1 ; for ( int i = index ; i < index + dividerIndex ; i ++ ) { if ( i >= buffer . length ) { break ; } buffer [ i ] = 0 ; } return index ; } buffer [ index ] = readByte ; index ++ ; } while ( index < buffer . length ) ; return index ; }
reads bytes from a given file reader until either a specified character sequence is read , the buffer is completely filled or the end of file is reached .
