Top Description Inners Fields Constructors Methods
com.jogamp.common.net

public Class Uri

extends Object
Class Inheritance
Imports
java.io.File, .UnsupportedEncodingException, java.net.MalformedURLException, .URISyntaxException, java.util.StringTokenizer, java.util.regex.Pattern, jogamp.common.Debug, com.jogamp.common.util.IOUtil, .PropertyAccess

This class implements an immutable Uri as defined by RFC 2396.

Character encoding is employed as defined by RFC 3986, see RFC 3986 section 2.1, while multibyte unicode characters are preserved in encoded parts.

    1 [scheme:]scheme-specific-part[#fragment]
    2 [scheme:][//authority]path[?query][#fragment]
    3 [scheme:][//[user-info@]host[:port]]path[?query][#fragment]

       scheme-specific-part: [//authority]path[?query]
       authority:            [user-info@]host[:port]

RFC 3986 section 2.2 Reserved Characters (January 2005)

! * ' ( ) ; : @ & = + $ , / ? # [ ]

RFC 3986 section 2.3 Unreserved Characters (January 2005)

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
a b c d e f g h i j k l m n o p q r s t u v w x y z
0 1 2 3 4 5 6 7 8 9 - _ . ~

Other characters in a Uri must be percent encoded.

Since
2.2.1

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
public static class
Uri.Encoded

Immutable RFC3986 encoded string.

Field Summary

Modifier and TypeField and Description
public final boolean
absolute

Indicating whether this Uri is absolute, i.e. has a scheme and hence an absolute scheme-specific-part.

public final Uri.Encoded
authority

Encoded authority part of scheme-specific-part, null if undefined.

public static final String
AUTHORITY_LEGAL

Valid charset for RFC 2396 authority, additional to legal alphanum characters.

private static final boolean
private static final boolean
private static final String
private static final String
public static final String
public static final String
FRAG_LEGAL

Valid charset for RFC 2396 fragment, additional to legal alphanum characters.

public final Uri.Encoded
fragment

Encoded fragment, null if undefined.

public static final char
public final boolean
hasAuthority

Indicating whether authority part is defined or not.

private int
public final Uri.Encoded
host

Encoded host part of authority and scheme-specific-part, null if undefined.

public static final String
public static final String
public final Uri.Encoded
input

Encoded input string used at construction, never null.

private Uri.ASCIIEncoded
inputASCII

Encoded input string used at construction, in US-ASCII encoding.

public static final String
public static final char
JAR_SCHEME_SEPARATOR

A JAR sub-protocol is separated from the JAR entry w/ this separator .

private final Object
private static final String
public final boolean
opaque

Indicating whether this Uri is opaque, i.e. non-hierarchical scheme-specific-part.

private static final int
PARSE_HINT_FIX_PATH

Usually used to fix a path from a previously contained and opaque Uri, i.e. getContainedUri().

public final Uri.Encoded
path

Encoded path part of scheme-specific-part, never null.

public static final String
PATH_LEGAL

Valid charset for RFC 2396 path, additional to legal alphanum characters.

private static final Pattern
public final int
port

Encoded port part of authority and scheme-specific-part, -1 if undefined.

private static final String
public final Uri.Encoded
query

Encoded query part of scheme-specific-part, null if undefined.

public static final String
QUERY_LEGAL

Valid charset for RFC 2396 query, additional to legal alphanum characters.

public static final char
public static final String
RESERVED

RFC 3986 section 2.2 Reserved Characters (January 2005)

+ alphanum

public static final String
public final Uri.Encoded
scheme

Encoded scheme, null if undefined.

public static final char
public final Uri.Encoded
schemeSpecificPart

Encoded scheme-specific-part, never null.

public static final String
SSP_LEGAL

Valid charset for RFC 2396 scheme-specific-part, additional to legal alphanum characters.

public static final String
UNRESERVED

RFC 3986 section 2.3 Unreserved Characters (January 2005)

+ alphanum

public final Uri.Encoded
userInfo

Encoded userinfo part of authority and scheme-specific-part, null if undefined.

public static final String
USERINFO_LEGAL

Valid charset for RFC 2396 authority's user-info, additional to legal alphanum characters.

Constructor Summary

AccessConstructor and Description
public
Uri(final Uri.Encoded
the RFC3986 encoded RFC2396 Uri representation to be parsed into a Uri object
uri
)

Creates a new Uri instance according to the given encoded string uri.

private
Uri(final Uri.Encoded input, final boolean expectServer, final int
TODO
parseHints
)

Method Summary

Modifier and TypeMethod and Description
private static void
appendUTF8(final StringBuilder sb, final byte[] buf, final int count)

public static Uri
cast(final String encodedUri)

Casts the given encoded String to a new Encoded instance used to create the resulting Uri instance via Uri(Encoded).

public final Uri
concat(final Uri.Encoded suffix)

Concatenates the given encoded string to the encoded uri of this instance and returns a new Uri instance with the result.

private String
public static Uri
create(final String
the unencoded scheme part of the Uri.
scheme
,
final String
the unencoded scheme-specific-part of the Uri.
ssp
,
final String
the unencoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given unencoded arguments.

public static Uri
create(final Uri.Encoded
the encoded scheme part of the Uri.
scheme
,
final Uri.Encoded
the encoded scheme-specific-part of the Uri.
ssp
,
final Uri.Encoded
the encoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given encoded arguments.

public static Uri
create(final String
the unencoded scheme part of the Uri.
scheme
,
final String
the unencoded user information of the Uri for authentication and authorization, null for undefined.
userinfo
,
String
the unencoded host name of the Uri, null for undefined.
host
,
final int
the port number of the Uri, -1 for undefined.
port
,
final String
the unencoded path to the resource on the host.
path
,
final String
the unencoded query part of the Uri to specify parameters for the resource.
query
,
final String
the unencoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given unencoded arguments.

public static Uri
create(final Uri.Encoded
the encoded scheme part of the Uri.
scheme
,
final Uri.Encoded
the encoded user information of the Uri for authentication and authorization, null for undefined.
userinfo
,
final Uri.Encoded
the encoded host name of the Uri, null for undefined.
host
,
final int
the port number of the Uri, -1 for undefined.
port
,
final Uri.Encoded
the encoded path to the resource on the host.
path
,
final Uri.Encoded
the encoded query part of the Uri to specify parameters for the resource.
query
,
final Uri.Encoded
the encoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given encoded arguments.

public static Uri
create(final String
the unencoded scheme part of the Uri.
scheme
,
final String
the unencoded host name of the Uri.
host
,
final String
the unencoded path to the resource on the host.
path
,
final String
the unencoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given unencoded arguments.

public static Uri
create(final Uri.Encoded
the encoded scheme part of the Uri.
scheme
,
final Uri.Encoded
the encoded host name of the Uri.
host
,
final Uri.Encoded
the encoded path to the resource on the host.
path
,
final Uri.Encoded
the encoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given encoded arguments.

public static Uri
create(final String
the unencoded scheme part of the Uri.
scheme
,
final String
the unencoded authority part of the Uri.
authority
,
final String
the unencoded path to the resource on the host.
path
,
final String
the unencoded query part of the Uri to specify parameters for the resource.
query
,
final String
the unencoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given unencoded arguments.

public static Uri
create(final Uri.Encoded
the encoded scheme part of the Uri.
scheme
,
final Uri.Encoded
the encoded authority part of the Uri.
authority
,
final Uri.Encoded
the encoded path to the resource on the host.
path
,
final Uri.Encoded
the encoded query part of the Uri to specify parameters for the resource.
query
,
final Uri.Encoded
the encoded fragment part of the Uri.
fragment
)

Creates a new Uri instance using the given encoded arguments.

private static final boolean
cutoffLastPathSegementImpl(final StringBuilder pathBuf, final boolean cutoffFile, final boolean cutoffDir, final Uri.Encoded appendPath)

private final Uri
cutoffLastPathSegementImpl(final boolean cutoffFile, final boolean cutoffDir, final Uri.Encoded appendPath)

public static String

Returns:

the decoded String or null if encoded was null.
decode
(final Uri.Encoded
Encoded instance to be decoded, may be null.
encoded
)

Safe Encoded#decode() call on optional encoded instance.

public static String

Returns:

java.lang.String The decoded version.
decode
(final String
The encoded string.
encoded
)

Decodes the string argument which is assumed to be encoded in the x-www-form-urlencoded MIME content type using the UTF-8 encoding scheme.

private static boolean
private static boolean
public static String

Returns:

java.lang.String the converted string
encode
(final String
the string to be encoded
vanilla
,
final String
extended character set, allowed to be preserved in the vanilla string
legal
)

All characters are encoded into their hexadecimal value prepended by '%', except:

  1. letters ('a'..'z', 'A'..'Z')
  2. numbers ('0'..'9')
  3. characters in the legal-set parameter
  4. others (unicode characters that are not in US-ASCII set, and are not ISO Control or are not ISO Space characters)
private static void
encodeChar2UTF8(final StringBuilder buf, final char ch)

public static String

Returns:

java.lang.String the converted string
encodeToASCIIString
(final String
string to be converted
unicode
)

Other characters, which are Unicode chars that are not US-ASCII, and are not ISO Control or are not ISO Space chars are not preserved and encoded into their hexidecimal value prepended by '%'.

public final boolean

Returns:

true if both Uri instances point to the same resource, false otherwise.
equals
(final Object
the Uri this instance has to be compared with.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
private boolean
equalsHexCaseInsensitive(final Uri.Encoded first, final Uri.Encoded second)

private static void
fail(final Uri.Encoded input, final String reason, final int p)

private static void
failExpecting(final Uri.Encoded input, final String expected, final int p)

public final Uri
getContainedUri()

If this instance's schemeSpecificPart contains a Uri itself, a sub-Uri, return schemeSpecificPart + # fragment via it's own new Uri instance.

public Uri
getDirectory()

Returns this Uri's directory Uri.

public final Uri.Encoded
getEncoded()

Returns the encoded input, never null.

private String
public final Uri
getNewQuery(final Uri.Encoded newQuery)

Returns a new Uri instance w/ the given new query newQuery.

public final Uri
getNormalized()

Normalizes this Uri's path and return the normalized form if it differs, otherwise this instance.

public final Uri
getParent()

Returns this Uri's parent directory Uri..

public Uri
getRelativeOf(final Uri.Encoded
denotes a relative path to be appended to this Uri's directory
appendPath
)

Returns a new Uri appending the given appendPath to this instance's directory.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
public final boolean
isFileScheme()

Returns true, if this instance is a file scheme, otherwise false.

public final boolean
isJarScheme()

Returns true, if this instance is a jar scheme, otherwise false.

private static boolean
private static boolean
isValidHexChar(final char c)

private boolean
isValidHost(final boolean expectServer, final Uri.Encoded host)

distinguish between IPv4, IPv6, domain name and validate it based on its type

private static boolean
isValidIP4Word(final String word)

private static boolean
isValidIP6Address(final String ipv6Address)

private static boolean
isValidIPv4Address(final String ipv4Address)

public Uri.ASCIIEncoded
toASCIIString()

Returns the encoded input encoded in US-ASCII.

public final File
toFile()

If this instance is a file scheme, implementation decodes [ "//"+authority ] + path, then it processes the result if File#separatorChar == '\\' as follows:

  • slash -> backslash
  • drop a starting single backslash, preserving windows UNC
public final String
toString()

Overrides java.lang.Object.toString.

Returns the encoded input as String, never null, same as getEncoded().
public final URI
toURI()

Returns a new URI instance using the encoded input string, new URI(uri.input), i.e. no re-encoding will be performed.

public final URI
toURIReencoded()

Returns a new URI instance based upon this instance.

public final URL
toURL()

Returns a new URL instance using the encoded input string, new URL(uri.input), i.e. no re-encoding will be performed.

private static int
validateAlphaNum(final String s, final String legal)

private static void
validateAuthority(final Uri.Encoded uri, final Uri.Encoded authority, final int index)

private static int
validateEncoded(final String
java.lang.String the string to be validated
encoded
,
final String
java.lang.String the characters allowed in the String s
legal
)

Validate a string by checking if it contains any characters other than:

  1. letters ('a'..'z', 'A'..'Z')
  2. numbers ('0'..'9')
  3. characters in the legal-set parameter
  4. others (unicode characters that are not in US-ASCII set, and are not ISO Control or are not ISO Space characters)
private static void
validateFragment(final Uri.Encoded uri, final Uri.Encoded fragment, final int index)

private static void
validatePath(final Uri.Encoded uri, final String path, final int index)

private static void
validateQuery(final Uri.Encoded uri, final Uri.Encoded query, final int index)

private static void
validateScheme(final Uri.Encoded uri, final Uri.Encoded scheme, final int index)

private static void
validateSsp(final Uri.Encoded uri, final String ssp, final int index)

private static void
validateUserinfo(final Uri.Encoded uri, final Uri.Encoded userinfo, final int index)

public static Uri
valueOf(final File
using slashified absolute-path for the path of the file schema, utilizing valueOfFilepath(String).
file
)

Creates a new Uri instance using the given File instance.

public static Uri
valueOf(final URI
A given URI instance
uri
)

Creates a new Uri instance using the given URI instance.

public static Uri
valueOf(final URL
A given URL instance
url
)

Creates a new Uri instance using the given URL instance, convenient wrapper for valueOf(URI) and URL#toURI().

public static Uri
valueOfFilepath(final String
the unencoded path of the file schema.
path
)

Creates a new Uri instance using the given file-path argument.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait