|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbb.net.UrlUtil
public final class UrlUtil
Provides static utility methods for dealing with URL
s.
This class is multithread safe: it is immutable (both its immediate state, as well as the deep state of its fields).
Nested Class Summary | |
---|---|
static class |
UrlUtil.UnitTest
See the Overview page of the project's javadocs for a general description of this unit test class. |
Field Summary | |
---|---|
private static int |
connectTimeout_default
|
private static String |
fileProtocol
|
private static String |
httpProtocol
|
private static String |
httpsProtocol
|
private static String |
mailtoProtocol
|
private static int |
readTimeout_default
|
Constructor Summary | |
---|---|
private |
UrlUtil()
This sole private constructor suppresses the default (public) constructor, ensuring non-instantiability outside of this class. |
Method Summary | |
---|---|
private static String |
analyseFileUrl(URL url)
|
private static String |
analyseHttpUrl(URL url)
|
private static String |
analyseMailtoUrl(URL url)
|
private static String |
analyseUnsupportedUrl(URL url)
|
static String |
analyseUrl(URL url)
Analyses the supplied URL. |
static String |
description(URL url)
Returns a string that describes every aspect of url. |
static byte[] |
drain(URL url)
Returns . |
static String |
drainIntoString(URL url)
Returns . |
static URL |
extractUrl(String urlString,
int lineNumber,
URL context)
First strips any quote marks from urlString via a call to removeQuotes, and then returns a new URL instance based off of urlString and context. |
static URL |
getFileUrl(File file)
Returns a new URL that points to file. |
static InputStream |
getInputStream(URL url)
Returns . |
static InputStream |
getInputStream(URL url,
int connectTimeout,
int readTimeout)
Creates a URLConnection for url with the specified connect and read timeouts, then opens and returns an InputStream from it. |
static OutputStream |
getOutputStream(URL url)
Returns . |
static OutputStream |
getOutputStream(URL url,
int connectTimeout,
int readTimeout)
Creates a URLConnection for url with the specified connect and read timeouts, then opens and returns an OutputStream from it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final String fileProtocol
private static final String httpProtocol
private static final String httpsProtocol
private static final String mailtoProtocol
private static final int connectTimeout_default
private static final int readTimeout_default
Constructor Detail |
---|
private UrlUtil()
Method Detail |
---|
public static URL getFileUrl(File file) throws IllegalArgumentException, MalformedURLException
IllegalArgumentException
- if file == null
MalformedURLException
- if file's path cannot be parsed into a proper URL specificationpublic static URL extractUrl(String urlString, int lineNumber, URL context) throws IllegalArgumentException, ParseException, MalformedURLException
urlString
- a String which should specify a URLlineNumber
- the line number where urlString is found; used only if throw a ParseExceptioncontext
- the context URL; used to resolve relative URLs; may be null if is not to be specified
IllegalArgumentException
- if urlString is null, or lineNumber < 0
ParseException
- if a leading but no matching trailing quote mark is present, or vice versa, on urlString
MalformedURLException
- if urlString cannot be parsed into a proper URL specificationpublic static byte[] drain(URL url) throws IllegalArgumentException, IllegalStateException, IOException, UnknownServiceException
StreamUtil.drain
( getInputStream
(url) )
.
IllegalArgumentException
- if url == null
IllegalStateException
- if url's inputStream turns out to hold more than Integer.MAX_VALUE
bytes (which cannot be held in a java array)
IOException
- if an I/O problem occurs
UnknownServiceException
- if the protocol does not support inputpublic static String drainIntoString(URL url) throws IllegalArgumentException, IllegalStateException, IOException, UnknownServiceException
StreamUtil.drainIntoString
( getInputStream
(url) )
.
IllegalArgumentException
- if url == null
IllegalStateException
- if url's inputStream turns out to hold more than Integer.MAX_VALUE
bytes (which cannot be held in a java array)
IOException
- if an I/O problem occurs
UnknownServiceException
- if the protocol does not support inputpublic static InputStream getInputStream(URL url) throws IllegalArgumentException, IOException, UnknownServiceException
getInputStream
( url, connectTimeout_default, readTimeout_default )
.
IllegalArgumentException
IOException
UnknownServiceException
public static InputStream getInputStream(URL url, int connectTimeout, int readTimeout) throws IllegalArgumentException, IOException, UnknownServiceException
IllegalArgumentException
- if url == null; connectTimeout or readTimeout is < 0
IOException
- if an I/O problem occurs
UnknownServiceException
- if the protocol does not support inputpublic static OutputStream getOutputStream(URL url) throws IllegalArgumentException, IOException, UnknownServiceException
getOutputStream
( url, connectTimeout_default, readTimeout_default )
.
IllegalArgumentException
IOException
UnknownServiceException
public static OutputStream getOutputStream(URL url, int connectTimeout, int readTimeout) throws IllegalArgumentException, IOException, UnknownServiceException
IllegalArgumentException
- if url == null; connectTimeout or readTimeout is < 0
IOException
- if an I/O problem occurs
UnknownServiceException
- if the protocol does not support inputpublic static String analyseUrl(URL url) throws IllegalArgumentException
url
- the URL to analyse
IllegalArgumentException
- if url == nullprivate static String analyseFileUrl(URL url)
private static String analyseHttpUrl(URL url)
private static String analyseMailtoUrl(URL url)
private static String analyseUnsupportedUrl(URL url)
public static String description(URL url) throws IllegalArgumentException
url
- a URL
IllegalArgumentException
- if url == null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |