public final class URLUtil
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.util.regex.Pattern |
DATA_URI_PATTERN |
static java.lang.String |
FILE_PROTOCOL |
static java.util.regex.Pattern |
FILE_URL_PATTERN |
static java.util.regex.Pattern |
HREF_PATTERN |
static java.lang.String |
HTTP_PROTOCOL |
static java.lang.String |
JAR_PROTOCOL |
static java.lang.String |
JAR_SEPARATOR |
static java.lang.String |
JRT_PROTOCOL |
static java.lang.String |
SCHEME_SEPARATOR |
static java.util.regex.Pattern |
URL_PATTERN |
static java.util.regex.Pattern |
URL_WITH_PARENS_PATTERN |
Modifier and Type | Method and Description |
---|---|
static boolean |
canContainUrl(java.lang.String line) |
static boolean |
containsScheme(java.lang.String url) |
static java.lang.String |
decode(java.lang.String string) |
static java.lang.String |
encodeURIComponent(java.lang.String s)
Encodes a URI component by replacing each instance of certain characters by one, two, three,
or four escape sequences representing the UTF-8 encoding of the character.
|
static TextRange |
findUrl(java.lang.CharSequence text,
int startOffset,
int endOffset)
Finds the first range in text containing URL.
|
static byte [] |
getBytesFromDataUri(java.lang.String dataUrl)
Extracts byte array from given data:URL string.
|
static java.net.URI |
getJarEntryUri(java.net.URI file,
java.lang.String pathInJar) |
static java.net.URL |
getJarEntryURL(java.io.File file,
java.lang.String pathInJar) |
static java.net.URL |
getJarEntryURL(java.net.URI file,
java.lang.String pathInJar) |
static boolean |
isDataUri(java.lang.String value) |
static java.io.InputStream |
openResourceStream(java.net.URL url) |
static java.io.InputStream |
openStream(java.net.URL url)
Opens a url stream.
|
static java.lang.String |
parseHostFromSshUrl(java.lang.String sshUrl) |
static ThreeState |
resourceExists(java.net.URL url)
Checks whether local resource specified by
url exists. |
static Pair<java.lang.String,java.lang.String> |
splitJarUrl(java.lang.String url)
Splits .jar URL along a separator and strips "jar" and "file" prefixes if any.
|
static java.lang.CharSequence |
unescapePercentSequences(java.lang.CharSequence s,
int from,
int end) |
static java.lang.String |
unescapePercentSequences(java.lang.String s) |
static java.io.File |
urlToFile(java.net.URL url) |
public static final java.lang.String SCHEME_SEPARATOR
public static final java.lang.String FILE_PROTOCOL
public static final java.lang.String HTTP_PROTOCOL
public static final java.lang.String JAR_PROTOCOL
public static final java.lang.String JRT_PROTOCOL
public static final java.lang.String JAR_SEPARATOR
public static final java.util.regex.Pattern DATA_URI_PATTERN
public static final java.util.regex.Pattern URL_PATTERN
public static final java.util.regex.Pattern URL_WITH_PARENS_PATTERN
public static final java.util.regex.Pattern FILE_URL_PATTERN
public static final java.util.regex.Pattern HREF_PATTERN
public static boolean canContainUrl(java.lang.String line)
URL_PATTERN
check should be used.public static java.io.InputStream openStream(java.net.URL url) throws java.io.IOException
URL.openStream()
. The
separate method is needed, since jar URLs open jars via JarFactory and thus keep them
mapped into memory.java.io.IOException
public static java.io.InputStream openResourceStream(java.net.URL url) throws java.io.IOException
java.io.IOException
public static ThreeState resourceExists(java.net.URL url)
url
exists. Returns ThreeState.UNSURE
if url
point to a remote resource.public static Pair<java.lang.String,java.lang.String> splitJarUrl(java.lang.String url)
public static java.io.File urlToFile(java.net.URL url)
public static java.lang.String unescapePercentSequences(java.lang.String s)
public static java.lang.CharSequence unescapePercentSequences(java.lang.CharSequence s, int from, int end)
public static boolean containsScheme(java.lang.String url)
public static boolean isDataUri(java.lang.String value)
public static byte [] getBytesFromDataUri(java.lang.String dataUrl)
dataUrl
- data:URL-like string (may be quoted)null
if it cannot be extracted.public static java.lang.String decode(java.lang.String string)
public static java.lang.String parseHostFromSshUrl(java.lang.String sshUrl)
public static java.net.URL getJarEntryURL(java.io.File file, java.lang.String pathInJar) throws java.net.MalformedURLException
java.net.MalformedURLException
public static java.net.URL getJarEntryURL(java.net.URI file, java.lang.String pathInJar) throws java.net.MalformedURLException
java.net.MalformedURLException
public static java.net.URI getJarEntryUri(java.net.URI file, java.lang.String pathInJar) throws java.net.URISyntaxException
java.net.URISyntaxException
public static java.lang.String encodeURIComponent(java.lang.String s)
s
- a component of a URIpublic static TextRange findUrl(java.lang.CharSequence text, int startOffset, int endOffset)
URL_PATTERN
matcher, but also finds URLs containing
matched set of parentheses.