Class URLConnectionTools
- java.lang.Object
- 
- org.biojava.nbio.structure.align.util.URLConnectionTools
 
- 
 public class URLConnectionTools extends Object A class that takes care about opening URLConnections and sets the proper timeouts- Since:
- 5.0
- Author:
- Andreas Prlic, Anthony Bradley
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intDEFAULT_CONNECTION_TIMEOUTThe default connection timeout in ms - 15 seconds
 - 
Constructor SummaryConstructors Constructor Description URLConnectionTools()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static InputStreamdoPOST(URL url, String data)Do a POST to a URL and return the response stream for further processing elsewhere.static InputStreamdoPOST(URL url, String data, int timeout)Do a POST to a URL and return the response stream for further processing elsewhere.static InputStreamgetInputStream(URL url)Connect to a URL and return result as an InputStream.static InputStreamgetInputStream(URL url, boolean acceptGzipEncoding, int timeout)Open a URL and return an InputStream to it if acceptGzipEncoding == true, use GZIPEncoding to compress communication.static InputStreamgetInputStream(URL url, int timeout)Connect to server and return result as an InputStream.static URLConnectionopenURLConnection(URL url)Open HttpURLConnection.static URLConnectionopenURLConnection(URL url, int timeout)Open HttpURLConnection.
 
- 
- 
- 
Field Detail- 
DEFAULT_CONNECTION_TIMEOUTpublic static final int DEFAULT_CONNECTION_TIMEOUT The default connection timeout in ms - 15 seconds- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
URLConnectionToolspublic URLConnectionTools() 
 
- 
 - 
Method Detail- 
openURLConnectionpublic static URLConnection openURLConnection(URL url, int timeout) throws IOException Open HttpURLConnection. Recommended way to open URL connections in Java 1.7 and 1.8. https://eventuallyconsistent.net/2011/08/02/working-with-urlconnection-and-timeouts/- Parameters:
- url- URL to open
- timeout- timeout in milli seconds
- Throws:
- IOException- an error in opening the URL
 
 - 
openURLConnectionpublic static URLConnection openURLConnection(URL url) throws IOException Open HttpURLConnection. Recommended way to open HttpURLConnections, since this take care of setting timeouts properly for java 1.4 and 1.5 uses the DEFAULT_CONNECTION_TIMEOUT (= 15 seconds)- Parameters:
- url- a URL to open a http connection to
- Returns:
- HttpURLConnect the opened connection
- Throws:
- IOException- an error in opening the URL
 
 - 
getInputStreampublic static InputStream getInputStream(URL url, int timeout) throws IOException Connect to server and return result as an InputStream. always asks for response to be in GZIP encodedThe caller is responsible to close the returned InputStream not to cause resource leaks. - Parameters:
- url- the URL to connect to
- timeout- the timeout for the connection
- Returns:
- an InputStreamof response
- Throws:
- IOException- due to an error opening the URL
 
 - 
getInputStreampublic static InputStream getInputStream(URL url) throws IOException Connect to a URL and return result as an InputStream. always asks for response to be in GZIP encodedThe caller is responsible to close the returned InputStream not to cause resource leaks. - Parameters:
- url- the input URL to be read
- Returns:
- an InputStreamof response
- Throws:
- IOException- due to an error opening the URL
 
 - 
getInputStreampublic static InputStream getInputStream(URL url, boolean acceptGzipEncoding, int timeout) throws IOException Open a URL and return an InputStream to it if acceptGzipEncoding == true, use GZIPEncoding to compress communication.The caller is responsible to close the returned InputStream not to cause resource leaks. - Parameters:
- url- the input URL to be read
- acceptGzipEncoding- whether to accept Gzip encoding
- timeout-
- Returns:
- an InputStreamof response
- Throws:
- IOException- due to an error opening the URL
 
 - 
doPOSTpublic static InputStream doPOST(URL url, String data) throws IOException Do a POST to a URL and return the response stream for further processing elsewhere.The caller is responsible to close the returned InputStream not to cause resource leaks. - Parameters:
- url- the input URL to be read
- data- the post data
- Returns:
- an InputStreamof response
- Throws:
- IOException- due to an error opening the URL
 
 - 
doPOSTpublic static InputStream doPOST(URL url, String data, int timeout) throws IOException Do a POST to a URL and return the response stream for further processing elsewhere.The caller is responsible to close the returned InputStream not to cause resource leaks. - Parameters:
- url- the input URL to be read
- data- the post data
- timeout-
- Returns:
- an InputStreamof response
- Throws:
- IOException- due to an error opening the URL
 
 
- 
 
-