Class Uri
- All Implemented Interfaces:
Proxy
GstUri object can be used to parse and split a URI string into its
constituent parts. Two GstUri objects can be joined to make a new GstUri
using the algorithm described in RFC3986.-
Constructor Summary
ConstructorsConstructorDescriptionUri(@Nullable String scheme, @Nullable String userinfo, @Nullable String host, int port, @Nullable String path, @Nullable String query, @Nullable String fragment) Creates a newGstUriobject with the given URI parts.Uri(MemorySegment address) Create a Uri proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanappendPath(@Nullable String relativePath) Append a path onto the end of the path in the URI.booleanappendPathSegment(@Nullable String pathSegment) Append a single path segment onto the end of the URI path.static StringDeprecated.Use GstURI instead.copy()Create a newGstUriobject with the same data as thisGstUriobject.booleanCompares twoGstUriobjects to see if they represent the same normalized URI.static @Nullable UrifromString(String uri) Parses a URI string into a newGstUriobject.static @Nullable UrifromStringEscaped(String uri) Parses a URI string into a newGstUriobject.@Nullable UrifromStringWithBase(String uri) Like gst_uri_from_string() but also joins with a base URI.@Nullable StringGet the fragment name from the URI ornullif it doesn't exist.@Nullable StringgetHost()Get the host name from the URI ornullif it doesn't exist.static @Nullable StringgetLocation(String uri) Extracts the location out of a given valid URI, ie.Get the media fragment table from the URI, as defined by "Media Fragments URI 1.0".@Nullable StringgetPath()Extract the path string from the URI object.Get a list of path segments from the URI.@Nullable StringExtract the path string from the URI object as a percent encoded URI path.intgetPort()Get the port number from the URI orGST_URI_NO_PORTif it doesn't exist.static @Nullable StringgetProtocol(String uri) Extracts the protocol out of a given valid URI.Get a list of the query keys from the URI.@Nullable StringGet a percent encoded URI query string from theuri.@Nullable StringgetQueryStringOrdered(@Nullable List<String> keys) Get a percent encoded URI query string from theuri,with query parameters in the order provided by thekeyslist.Get the query table from the URI.@Nullable StringgetQueryValue(String queryKey) Get the value associated with thequeryKeykey.@Nullable StringGet the scheme name from the URI ornullif it doesn't exist.static @Nullable TypegetType()Get the GType of the Uri class@Nullable StringGet the userinfo (usually in the form "username:password") from the URI ornullif it doesn't exist.static booleanhasProtocol(String uri, String protocol) Checks if the protocol of a given valid URI matchesprotocol.booleanTests the this Uri to see if it is normalized.static booleanTests if the given string is a valid URI identifier.booleanCheck if it is safe to write to thisGstUri.@Nullable UriJoin a reference URI onto a base URI using the method from RFC 3986.static @Nullable StringjoinStrings(String baseUri, String refUri) This is a convenience function to join two URI strings and return the result.Make theGstUriwritable.newWithBase(@Nullable String scheme, @Nullable String userinfo, @Nullable String host, int port, @Nullable String path, @Nullable String query, @Nullable String fragment) Like gst_uri_new(), but joins the new URI onto a base URI.booleanNormalization will remove extra path segments ("." and "..") from the URI.static booleanprotocolIsSupported(URIType type, String protocol) Checks if an element exists that supports the given URI protocol.static booleanprotocolIsValid(String protocol) Tests if the given string is a valid protocol identifier.booleanqueryHasKey(String queryKey) Check if there is a query table entry for thequeryKeykey.ref()Add a reference to thisGstUriobject.booleanremoveQueryKey(String queryKey) Remove an entry from the query table by key.booleansetFragment(@Nullable String fragment) Sets the fragment string in the URI.booleanSet or unset the host for the URI.booleanSets or unsets the path in the URI.booleansetPathSegments(@Nullable List<String> pathSegments) Replace the path segments list in the URI.booleansetPathString(String path) Sets or unsets the path in the URI.booleansetPort(int port) Set or unset the port number for the URI.booleansetQueryString(@Nullable String query) Sets or unsets the query table in the URI.booleansetQueryTable(@Nullable HashTable<String, String> queryTable) Set the query table to use in the URI.booleansetQueryValue(String queryKey, @Nullable String queryValue) This inserts or replaces a key in the query table.booleanSet or unset the scheme for the URI.booleansetUserinfo(String userinfo) Set or unset the user information for the URI.toString()Convert the URI to a string.toStringWithKeys(@Nullable List<String> keys) Convert the URI to a string, with the query arguments in a specific order.voidunref()Decrement the reference count to thisGstUriobject.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Uri
Create a Uri proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Uri
public Uri(@Nullable String scheme, @Nullable String userinfo, @Nullable String host, int port, @Nullable String path, @Nullable String query, @Nullable String fragment) Creates a newGstUriobject with the given URI parts. The path and query strings will be broken down into their elements. All strings should not be escaped except where indicated.- Parameters:
scheme- The scheme for the new URI.userinfo- The user-info for the new URI.host- The host name for the new URI.port- The port number for the new URI orGST_URI_NO_PORT.path- The path for the new URI with '/' separating path elements.query- The query string for the new URI with '&' separating query elements. Elements containing '&' characters should encode them as "%26".fragment- The fragment name for the new URI.- Since:
- 1.6
-
-
Method Details
-
getType
-
construct
Deprecated.Use GstURI instead.Constructs a URI for a given valid protocol and location.Free-function: g_free
- Parameters:
protocol- Protocol for URIlocation- Location for URI- Returns:
- a new string for this URI.
-
fromString
-
fromStringEscaped
Parses a URI string into a newGstUriobject. Will return NULL if the URI cannot be parsed. This is identical to gst_uri_from_string() except that the userinfo and fragment components of the URI will not be unescaped while parsing.Use this when you need to extract a username and password from the userinfo such as https://user:password
example.comsince either may contain a URI-escaped ':' character. gst_uri_from_string() will unescape the entire userinfo component, which will make it impossible to know which ':' delineates the username and password.The same applies to the fragment component of the URI, such as https://example.com/path
fragmentwhich may contain a URI-escaped ''.- Parameters:
uri- The URI string to parse.- Returns:
- A new
GstUriobject, or NULL. - Since:
- 1.18
-
getLocation
Extracts the location out of a given valid URI, ie. the protocol and "://" are stripped from the URI, which means that the location returned includes the hostname if one is specified. The returned string must be freed using g_free().Free-function: g_free
- Parameters:
uri- A URI string- Returns:
- the location for this URI. Returns
nullif the URI isn't valid. If the URI does not contain a location, an empty string is returned.
-
getProtocol
-
hasProtocol
-
isValid
Tests if the given string is a valid URI identifier. URIs start with a valid scheme followed by ":" and maybe a string identifying the location.- Parameters:
uri- A URI string- Returns:
trueif the string is a valid URI
-
joinStrings
This is a convenience function to join two URI strings and return the result. The returned string should be g_free()'d after use.- Parameters:
baseUri- The percent-encoded base URI.refUri- The percent-encoded reference URI to join to thebaseUri.- Returns:
- A string representing the percent-encoded join of the two URIs.
- Since:
- 1.6
-
protocolIsSupported
Checks if an element exists that supports the given URI protocol. Note that a positive return value does not imply that a subsequent call to gst_element_make_from_uri() is guaranteed to work.- Parameters:
type- Whether to check for a source or a sinkprotocol- Protocol that should be checked for (e.g. "http" or "smb")- Returns:
true
-
protocolIsValid
Tests if the given string is a valid protocol identifier. Protocols must consist of alphanumeric characters, '+', '-' and '.' and must start with a alphabetic character. See RFC 3986 Section 3.1.- Parameters:
protocol- A string- Returns:
trueif the string is a valid protocol identifier,falseotherwise.
-
appendPath
Append a path onto the end of the path in the URI. The path is not normalized, callgst_uri_normalize() to normalize the path.- Parameters:
relativePath- Relative path to append to the end of the current path.- Returns:
trueif the path was appended successfully.- Since:
- 1.6
-
appendPathSegment
Append a single path segment onto the end of the URI path.- Parameters:
pathSegment- The path segment string to append to the URI path.- Returns:
trueif the path was appended successfully.- Since:
- 1.6
-
copy
Create a newGstUriobject with the same data as thisGstUriobject. If this Uri isnullthen returnsnull.- Returns:
- A new
GstUriobject which is a copy of thisGstUriornull. - Since:
- 1.6
-
equal
Compares twoGstUriobjects to see if they represent the same normalized URI.- Parameters:
second- SecondGstUrito compare.- Returns:
trueif the normalized versions of the two URI's would be equal.- Since:
- 1.6
-
fromStringWithBase
-
getFragment
Get the fragment name from the URI ornullif it doesn't exist. If this Uri isnullthen returnsnull.- Returns:
- The host name from the
GstUriobject ornull. - Since:
- 1.6
-
getHost
Get the host name from the URI ornullif it doesn't exist. If this Uri isnullthen returnsnull.- Returns:
- The host name from the
GstUriobject ornull. - Since:
- 1.6
-
getMediaFragmentTable
Get the media fragment table from the URI, as defined by "Media Fragments URI 1.0". Hash table returned by this API is a list of "key-value" pairs, and the each pair is generated by splitting "URI fragment" per "&" sub-delims, then "key" and "value" are split by "=" sub-delims. The "key" returned by this API may be undefined keyword by standard. A value may benullto indicate that the key should appear in the fragment string in the URI, but does not have a value. Free the returnedGHashTablewithg_hash_table_unref() when it is no longer required. Modifying this hash table does not affect the fragment in the URI.See more about Media Fragments URI 1.0 (W3C) at https://www.w3.org/TR/media-frags/
- Returns:
- The fragment hash table from the URI.
- Since:
- 1.12
-
getPath
Extract the path string from the URI object.- Returns:
- The path from the URI. Once finished with the string should be g_free()'d.
- Since:
- 1.6
-
getPathSegments
-
getPathString
Extract the path string from the URI object as a percent encoded URI path.- Returns:
- The path from the URI. Once finished with the string should be g_free()'d.
- Since:
- 1.6
-
getPort
public int getPort()Get the port number from the URI orGST_URI_NO_PORTif it doesn't exist. If this Uri isnullthen returnsGST_URI_NO_PORT.- Returns:
- The port number from the
GstUriobject orGST_URI_NO_PORT. - Since:
- 1.6
-
getQueryKeys
-
getQueryString
Get a percent encoded URI query string from theuri.- Returns:
- A percent encoded query string. Use g_free() when no longer needed.
- Since:
- 1.6
-
getQueryStringOrdered
Get a percent encoded URI query string from theuri,with query parameters in the order provided by thekeyslist. Only parameter keys in the list will be added to the resulting URI string. This method can be used by retrieving the keys with gst_uri_get_query_keys() and then sorting the list, for example.- Parameters:
keys- A GList containing the query argument key strings.- Returns:
- A percent encoded query string. Use g_free() when no longer needed.
- Since:
- 1.24
-
getQueryTable
Get the query table from the URI. Keys and values in the table are freed with g_free when they are deleted. A value may benullto indicate that the key should appear in the query string in the URI, but does not have a value. Free the returnedGHashTablewithg_hash_table_unref() when it is no longer required. Modifying this hash table will modify the query in the URI.- Returns:
- The query hash table from the URI.
- Since:
- 1.6
-
getQueryValue
Get the value associated with thequeryKeykey. Will returnnullif the key has no value or if the key does not exist in the URI query table. Becausenullis returned for both missing keys and keys with no value, you should use gst_uri_query_has_key() to determine if a key is present in the URI query.- Parameters:
queryKey- The key to lookup.- Returns:
- The value for the given key, or
nullif not found. - Since:
- 1.6
-
getScheme
Get the scheme name from the URI ornullif it doesn't exist. If this Uri isnullthen returnsnull.- Returns:
- The scheme from the
GstUriobject ornull.
-
getUserinfo
Get the userinfo (usually in the form "username:password") from the URI ornullif it doesn't exist. If this Uri isnullthen returnsnull.- Returns:
- The userinfo from the
GstUriobject ornull. - Since:
- 1.6
-
isNormalized
public boolean isNormalized()Tests the this Uri to see if it is normalized. Anullthis Uri is considered to be normalized.- Returns:
- TRUE if the URI is normalized or is
null. - Since:
- 1.6
-
isWritable
public boolean isWritable()Check if it is safe to write to thisGstUri.Check if the refcount of this Uri is exactly 1, meaning that no other reference exists to the
GstUriand that theGstUriis therefore writable.Modification of a
GstUrishould only be done after verifying that it is writable.- Returns:
trueif it is safe to write to the object.- Since:
- 1.6
-
join
Join a reference URI onto a base URI using the method from RFC 3986. If either URI isnullthen the other URI will be returned with the ref count increased.- Parameters:
refUri- The reference URI to join onto the base URI.- Returns:
- A
GstUriwhich represents the base with the reference URI joined on. - Since:
- 1.6
-
makeWritable
Make theGstUriwritable.Checks if this Uri is writable, and if so the original object is returned. If not, then a writable copy is made and returned. This gives away the reference to this Uri and returns a reference to the new
GstUri. If this Uri isnullthennullis returned.- Returns:
- A writable version of
uri. - Since:
- 1.6
-
newWithBase
public Uri newWithBase(@Nullable String scheme, @Nullable String userinfo, @Nullable String host, int port, @Nullable String path, @Nullable String query, @Nullable String fragment) Like gst_uri_new(), but joins the new URI onto a base URI.- Parameters:
scheme- The scheme for the new URI.userinfo- The user-info for the new URI.host- The host name for the new URI.port- The port number for the new URI orGST_URI_NO_PORT.path- The path for the new URI with '/' separating path elements.query- The query string for the new URI with '&' separating query elements. Elements containing '&' characters should encode them as "%26".fragment- The fragment name for the new URI.- Returns:
- The new URI joined onto
base. - Since:
- 1.6
-
normalize
public boolean normalize()Normalization will remove extra path segments ("." and "..") from the URI. It will also convert the scheme and host name to lower case and any percent-encoded values to uppercase.The
GstUriobject must be writable. Check with gst_uri_is_writable() or use gst_uri_make_writable() first.- Returns:
- TRUE if the URI was modified.
- Since:
- 1.6
-
queryHasKey
Check if there is a query table entry for thequeryKeykey.- Parameters:
queryKey- The key to lookup.- Returns:
trueifqueryKeyexists in the URI query table.- Since:
- 1.6
-
ref
Add a reference to thisGstUriobject. See gst_mini_object_ref() for further info.- Returns:
- This object with the reference count incremented.
- Since:
- 1.6
-
removeQueryKey
Remove an entry from the query table by key.- Parameters:
queryKey- The key to remove.- Returns:
trueif the key existed in the table and was removed.- Since:
- 1.6
-
setFragment
Sets the fragment string in the URI. Use a value ofnullinfragmentto unset the fragment string.- Parameters:
fragment- The fragment string to set.- Returns:
trueif the fragment was set/unset successfully.- Since:
- 1.6
-
setHost
Set or unset the host for the URI.- Parameters:
host- The new host string to set ornullto unset.- Returns:
trueif the host was set/unset successfully.- Since:
- 1.6
-
setPath
Sets or unsets the path in the URI.- Parameters:
path- The new path to set with path segments separated by '/', or usenullto unset the path.- Returns:
trueif the path was set successfully.- Since:
- 1.6
-
setPathSegments
-
setPathString
Sets or unsets the path in the URI.- Parameters:
path- The new percent encoded path to set with path segments separated by '/', or usenullto unset the path.- Returns:
trueif the path was set successfully.- Since:
- 1.6
-
setPort
public boolean setPort(int port) Set or unset the port number for the URI.- Parameters:
port- The new port number to set orGST_URI_NO_PORTto unset.- Returns:
trueif the port number was set/unset successfully.- Since:
- 1.6
-
setQueryString
Sets or unsets the query table in the URI.- Parameters:
query- The new percent encoded query string to use to populate the query table, or usenullto unset the query table.- Returns:
trueif the query table was set successfully.- Since:
- 1.6
-
setQueryTable
Set the query table to use in the URI. The old table is unreferenced and a reference to the new one is used instead. A value ifnullforqueryTablewill remove the query string from the URI.- Parameters:
queryTable- The new query table to use.- Returns:
trueif the new table was successfully used for the query table.- Since:
- 1.6
-
setQueryValue
This inserts or replaces a key in the query table. AqueryValueofnullindicates that the key has no associated value, but will still be present in the query string.- Parameters:
queryKey- The key for the query entry.queryValue- The value for the key.- Returns:
trueif the query table was successfully updated.- Since:
- 1.6
-
setScheme
Set or unset the scheme for the URI.- Parameters:
scheme- The new scheme to set ornullto unset the scheme.- Returns:
trueif the scheme was set/unset successfully.- Since:
- 1.6
-
setUserinfo
Set or unset the user information for the URI.- Parameters:
userinfo- The new user-information string to set ornullto unset.- Returns:
trueif the user information was set/unset successfully.- Since:
- 1.6
-
toString
Convert the URI to a string.Returns the URI as held in this object as a
gchar* nul-terminated string. The caller should g_free() the string once they are finished with it. The string is put together as described in RFC 3986. -
toStringWithKeys
Convert the URI to a string, with the query arguments in a specific order. Only the keys in thekeyslist will be added to the resulting string.Returns the URI as held in this object as a
gchar* nul-terminated string. The caller should g_free() the string once they are finished with it. The string is put together as described in RFC 3986.- Parameters:
keys- A GList containing the query argument key strings.- Returns:
- The string version of the URI.
- Since:
- 1.24
-
unref
public void unref()Decrement the reference count to thisGstUriobject.If the reference count drops to 0 then finalize this object.
See gst_mini_object_unref() for further info.
- Since:
- 1.6
-