code: private void setupInputStream() throws IOException {
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  
      // set timeout for connecting and reading
      connection.setConnectTimeout(httpTimeout);
      connection.setReadTimeout(httpTimeout);
  
      if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        throw new IOException("Fetch of " + url + " failed with status code "
            + connection.getResponseCode() + "\nResponse message:\n"
            + connection.getResponseMessage());
      }
  
      String contentLength = connection
          .getHeaderField(TransferFsImage.CONTENT_LENGTH);
      if (contentLength != null) {
        // store image size
        advertisedSize = Long.parseLong(contentLength);
        if (advertisedSize <= 0) {
          throw new IOException("Invalid " + TransferFsImage.CONTENT_LENGTH
              + " header: " + contentLength);
        }
      } else {
        throw new IOException(TransferFsImage.CONTENT_LENGTH
            + " header is not provided " + "by the server when trying to fetch "
            + url);
      }
  
      // get the digest
      digest = TransferFsImage.parseMD5Header(connection);
      if (digest == null) {
        // digest must be provided, otherwise the image is not valid
        throw new IOException("Image digest not provided for url: " + url);
      }
  
      // get the input stream directly from the connection
      inputStream = connection.getInputStream();
      initialized = true;
    }
docs: Get input stream for the image through http connection.