private boolean loadData() throws IOException {
    if (currentChunk == null || !currentChunk.hasRemaining()) {
      if (currentChunk != null) {
        asyncWritableChannel.resolveOldestChunk(null);
      }
      try {
        while (true) {
          currentChunk = asyncWritableChannel.getNextChunk();
          if (currentChunk != null && !currentChunk.hasRemaining()) {
            asyncWritableChannel.resolveOldestChunk(null);
          } else {
            break;
          }
        }
      } catch (InterruptedException e) {
        throw new IllegalStateException(e);
      }
    }
    if (currentChunk == null) {
      if (callback.exception != null) {
        if (callback.exception instanceof IOException) {
          throw (IOException) callback.exception;
        } else {
          throw new IllegalStateException(callback.exception);
        }
      } else if (bytesAvailable != 0) {
        throw new IllegalStateException("All the bytes available could not be read");
      }
    }
    return currentChunk != null;
  }
Loads more data for reading. Blocks until data is either available or no more data is expected.
@return {@code true} if data is available for reading. {@link false} otherwise.
@throws IllegalStateException if the wait for the next chunk is interrupted.
@throws IOException if there is any problem with I/O.
ambry-commons/src/main/java/com/github/ambry/commons/ReadableStreamChannelInputStream.java