protected boolean fill(InputStream inputStream) throws IOException {

    int nextEnd = this.buffersEndIndex + 1;
    if (nextEnd >= this.buffers.length) {
      nextEnd = 0;
    }
    boolean todo = true;
    while (todo) {
      ByteArrayBufferImpl buffer = this.buffers[nextEnd];
      if (nextEnd == this.buffersIndex) {
        if (buffer.hasNext()) {
          break;
        } else {
          // the buffer was initially completely empty...
          nextBuffer();
          todo = false;
        }
      }
      if (nextEnd != this.buffersIndex) {
        int bytes = inputStream.read(buffer.getBytes());
        if (bytes == 0) {
          // strange API but however give it another try...
          bytes = inputStream.read(buffer.getBytes());
        }
        if (bytes > 0) {
          buffer.setCurrentIndex(0);
          buffer.setMaximumIndex(bytes - 1);
        } else {
          assert (bytes == -1);
          return true;
        }
      }
      this.buffersEndIndex = nextEnd;
      nextEnd++;
      if (nextEnd >= this.buffers.length) {
        nextEnd = 0;
      }
    }
    return false;
  }
protected boolean fill ( InputStream inputStream ) throws IOException { int nextEnd = this . buffersEndIndex + 1 ; if ( nextEnd >= this . buffers . length ) { nextEnd = 0 ; } boolean todo = true ; while ( todo ) { ByteArrayBufferImpl buffer = this . buffers [ nextEnd ] ; if ( nextEnd == this . buffersIndex ) { if ( buffer . hasNext ( ) ) { break ; } else { nextBuffer ( ) ; todo = false ; } } if ( nextEnd != this . buffersIndex ) { int bytes = inputStream . read ( buffer . getBytes ( ) ) ; if ( bytes == 0 ) { bytes = inputStream . read ( buffer . getBytes ( ) ) ; } if ( bytes > 0 ) { buffer . setCurrentIndex ( 0 ) ; buffer . setMaximumIndex ( bytes - 1 ) ; } else { assert ( bytes == - 1 ) ; return true ; } } this . buffersEndIndex = nextEnd ; nextEnd ++ ; if ( nextEnd >= this . buffers . length ) { nextEnd = 0 ; } } return false ; }
This method fills this buffer using the given {@code inputStream}. If the buffer is already filled, this method
will have no effect and return {@code false}.

@param inputStream is the {@link InputStream} providing the data to fill this buffer with.
@throws IOException if caused by the {@code inputStream} whilst reading.
@return {@code true} if the end of the stream was encountered while (re)filling this buffer, {@code false}
otherwise.