code: private static void prepareConnection(URLConnection connection, int timeout, SSLSocketFactory sslFactory) {
          if (timeout == 0) {
              throw new IllegalArgumentException("Zero (infinite) timeouts not permitted");
          }
          connection.setConnectTimeout(timeout);
          connection.setReadTimeout(timeout);
          connection.setDoInput(true); // whether we want to read from the connection
          connection.setDoOutput(false); // whether we want to write to the connection
  
          if(connection instanceof HttpsURLConnection && sslFactory != null) {
              ((HttpsURLConnection)connection).setSSLSocketFactory(sslFactory);
          }
      }
docs: /*
  Prepare connection by setting connectTimeout and readTimeout to timeout,
  doOutput to false and doInput to true.
  
  Throws IllegalArgumentException on zero (infinite) timeout.