code: public boolean ensureBytes(int n) throws IOException {
      int required = n - endIndex + index;
      while (required > 0) {
        if (!readMore(required)) {
          return false;
        }
        required = n - endIndex + index;
      }
      return true;
    }
docs: Ensures that the buffer contains at least n bytes. This method invalidates the buffer and index
  fields.
  
  @param n The amount of bytes to ensure exists in buffer
  @return true if required bytes are available and false if EOF
  @throws IOException If reading of the wrapped stream failed.