public static URLConnection createConnectionToURL ( final String url , final Map < String , String > requestHeaders ) throws IOException { final URL connectionURL = URLUtility . stringToUrl ( url ) ; if ( connectionURL == null ) { throw new IOException ( "Invalid url format: " + url ) ; } final URLConnection urlConnection = connectionURL . openConnection ( ) ; urlConnection . setConnectTimeout ( CONNECTION_TIMEOUT ) ; urlConnection . setReadTimeout ( READ_TIMEOUT ) ; if ( requestHeaders != null ) { for ( final Map . Entry < String , String > entry : requestHeaders . entrySet ( ) ) { urlConnection . setRequestProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } } return urlConnection ; }
Create URLConnection instance .