package com.nordnetab.chcp.main.utils; import java.io.IOException; import java.net.URL; import java.net.URLConnection; import java.util.Map; public class URLConnectionHelper { private static final int CONNECTION_TIMEOUT = 30000; private static final int READ_TIMEOUT = 30000; public static URLConnection createConnectionToURL(String str, Map<String, String> map) throws IOException { URL stringToUrl = URLUtility.stringToUrl(str); if (stringToUrl != null) { URLConnection openConnection = stringToUrl.openConnection(); openConnection.setConnectTimeout(30000); openConnection.setReadTimeout(30000); if (map != null) { for (Map.Entry<String, String> entry : map.entrySet()) { openConnection.setRequestProperty(entry.getKey(), entry.getValue()); } } return openConnection; } throw new IOException("Invalid url format: " + str); } }