Here you can find the source of openStream(URL url, int connectTimeout, int readTimeout)
Parameter | Description |
---|---|
IOException | an exception |
public static InputStream openStream(URL url, int connectTimeout, int readTimeout) throws IOException
//package com.java2s; /*//from w w w . j av a 2s .co m * Copyright 2010-2012 University of Toronto * * 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.*; import java.net.*; public class Main { private static final int CONNECT_TIMEOUT = 30000; private static final int READ_TIMEOUT = 30000; /** * Open a stream for the given URL with the CONNECT_TIMEOUT and READ_TIMEOUT. * @throws IOException */ public static InputStream openStream(URL url) throws IOException { return openStream(url, CONNECT_TIMEOUT, READ_TIMEOUT); } /** * Open a stream for the given URL with custom timeouts * @throws IOException */ public static InputStream openStream(URL url, int connectTimeout, int readTimeout) throws IOException { URLConnection conn = url.openConnection(); conn.setConnectTimeout(connectTimeout); conn.setReadTimeout(readTimeout); return conn.getInputStream(); } }