Package de.stefanfrings.utils
Class CombinedURL
- java.lang.Object
-
- de.stefanfrings.utils.CombinedURL
-
public class CombinedURL extends Object
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
Constructors Constructor Description CombinedURL(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URLConnection
connect(int connTimeout, int readTimeout)
Open a connection to the URL.URLConnection
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.Proxy
getProxy()
Get a Proxy instance from proxy URL.URL
getProxyURL()
Get the proxy URL part of this combined URL.URL
getserverURL()
Get the server URL part of this combined URL.String
toString()
Get the combined URL as string.
-
-
-
Constructor Detail
-
CombinedURL
public CombinedURL(URL proxyURL, URL serverURL) throws MalformedURLException
Constructor that takes proxy and server URL.- Parameters:
proxyURL
- proxy settingsserverURL
- server settings- Throws:
MalformedURLException
- If the URL is invalid.
-
CombinedURL
public CombinedURL(String proxy, String server) throws MalformedURLException
Constructor that takes proxy and server URL as string.- Parameters:
proxy
- proxy settingsserver
- server settings- Throws:
MalformedURLException
- If the URL is invalid.
-
CombinedURL
public CombinedURL(String combined) throws MalformedURLException
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 Detail
-
getProxyURL
public URL getProxyURL()
Get the proxy URL part of this combined URL.- Returns:
- proxy URL
-
getserverURL
public URL getserverURL()
Get the server URL part of this combined URL.- Returns:
- server URL
-
toString
public String toString()
Get the combined URL as string.
-
getProxy
public Proxy getProxy() throws MalformedURLException
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,String> httpPostData, String httpPostEncoding) throws IOException
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
public URLConnection connect(int connTimeout, int readTimeout) throws IOException
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.
-
-