Here you can find the source of getInputStreamFromUrl(String urlString)
private static InputStream getInputStreamFromUrl(String urlString) throws IOException
//package com.java2s; /******************************************************************************* * Copyright 2013 Johns Hopkins University * //from w w w .j a va2 s .c o m * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { private static InputStream getInputStreamFromUrl(String urlString) throws IOException { URL url = new URL(urlString); if (!url.getProtocol().toLowerCase().startsWith("http")) throw new UnsupportedOperationException( "URL \"" + urlString + "\" has an unsupported protocol, \"" + url.getProtocol() + "\"."); else { HttpURLConnection urlConn = (HttpURLConnection) new URL(urlString).openConnection(); urlConn.setConnectTimeout(10000); // millis -- 10 seconds urlConn.setRequestMethod("GET"); urlConn.connect(); return urlConn.getInputStream(); } } }