Package de.stefanfrings.utils
Class CombinedURL
java.lang.Object
de.stefanfrings.utils.CombinedURL
Extended version of the URL class, supports proxy and authentication, can send
HTTP header and post parameters.
Examples:
- http://stefan:password@www.whatever.com/private/music.mp3
- ftp://stefan:password@ftp.whatever.com/private/music.mp3
- http://freeproxy:8080?http://www.google.com/search?q=linux
- http://freeproxy:8080?http://stefan:password@www.whatever.com/private/music.mp3
- http://stefan:password@wwwproxy:8080?http://stefan:password@www.whatever.com/private/music.mp3
The syntax of a combined URL is:
- [proxy?]server
The syntax of the optional proxy part is:
- http://[username:password@]host:port
- socks://[username:password@]host:port
The syntax of server part is:
- http://[username:password@]host[:port]/[path/][filename][?parameters]
- ftp://[username:password@]host[:port]/[path/]filename
- file:///[path/]filename (reative to current working directory)
- file:////[path/]filename (Unix absolute path)
- file://drive:/[path/]filename (Windows absolute path)
- file://server/[path/]filename (Windows absolute path)
Other protocols might work but have not been tested.
- Author:
- Stefan Frings, http://stefanfrings.de/javautils
-
Constructor Summary
ConstructorsConstructorDescriptionCombinedURL(String combined) Constructor that takes a server URL or combined URL as string.CombinedURL(String proxy, String server) Constructor that takes proxy and server URL as string.CombinedURL(URL proxyURL, URL serverURL) Constructor that takes proxy and server URL. -
Method Summary
Modifier and TypeMethodDescriptionconnect(int connTimeout, int readTimeout) Open a connection to the URL.connect(int connTimeout, int readTimeout, Map<String, String> httpRequestHeaderParams, Map<String, String> httpPostData, String httpPostEncoding) Open a connection to the URL, with optional HTTP specific parameters.getProxy()Get a Proxy instance from proxy URL.Get the proxy URL part of this combined URL.Get the server URL part of this combined URL.toString()Get the combined URL as string.
-
Constructor Details
-
CombinedURL
Constructor that takes proxy and server URL.- Parameters:
proxyURL- proxy settingsserverURL- server settings- Throws:
MalformedURLException- If the URL is invalid.
-
CombinedURL
Constructor that takes proxy and server URL as string.- Parameters:
proxy- proxy settingsserver- server settings- Throws:
MalformedURLException- If the URL is invalid.
-
CombinedURL
Constructor that takes a server URL or combined URL as string.This constructor detect automatically whether the argument contains the optional proxy URL followed by "?" followed by the mandatory server URL.
- Parameters:
combined- Combined string with optional proxy URL and server URL- Throws:
MalformedURLException- If the URL is invalid.
-
-
Method Details
-
getProxyURL
Get the proxy URL part of this combined URL.- Returns:
- proxy URL
-
getserverURL
Get the server URL part of this combined URL.- Returns:
- server URL
-
toString
Get the combined URL as string. -
getProxy
Get a Proxy instance from proxy URL.- Returns:
- A Proxy or Proxy.NO_PROXY
- Throws:
MalformedURLException- If the URL is not properly formed.
-
connect
public URLConnection connect(int connTimeout, int readTimeout, Map<String, String> httpRequestHeaderParams, Map<String, throws IOExceptionString> httpPostData, String httpPostEncoding) Open a connection to the URL, with optional HTTP specific parameters.To read data, use
TextReader.readText(URLConnection con, String defaultEncoding)orURLConnection.getInputStream().- Parameters:
connTimeout- Timeout for connection in ms.readTimeout- Timeout for reading in ms.httpRequestHeaderParams- Pairs of name+value of request header parameters, may be null.httpPostData- Pairs of name+value to send like HTML forms, may be null.httpPostEncoding- Encoding of the form data, typically UTF-8.- Returns:
- An open URLConnection, don't forget to close it!
- Throws:
IOException- In case of an I/O error.
-
connect
Open a connection to the URL.To read data, use
TextReader.readText(URLConnection con, String defaultEncoding)orURLConnection.getInputStream().- Parameters:
connTimeout- Timeout for connection in ms.readTimeout- Timeout for reading in ms.- Returns:
- An open URLConnection, don't forget to close it!
- Throws:
IOException- In case of an I/O error.
-