Share via


UrlBuilder Class

  • java.lang.Object
    • com.azure.core.util.UrlBuilder

public final class UrlBuilder

A builder class that is used to create URLs.

Constructor Summary

Constructor Description
UrlBuilder()

Creates a new instance of UrlBuilder.

Method Summary

Modifier and Type Method and Description
UrlBuilder addQueryParameter(String queryParameterName, String queryParameterEncodedValue)

Append the provided query parameter name and encoded value to query string for the final URL.

UrlBuilder clearQuery()

Clear the query that will be used to build the final URL.

String getHost()

Get the host that has been assigned to this UrlBuilder.

String getPath()

Get the path that has been assigned to this UrlBuilder.

Integer getPort()

Get the port that has been assigned to this UrlBuilder.

Map<String,String> getQuery()

Get a view of the query that has been assigned to this UrlBuilder.

String getQueryString()

Returns the query string currently configured in this UrlBuilder instance.

String getScheme()

Get the scheme/protocol that has been assigned to this UrlBuilder.

static UrlBuilder parse(String url)

Parses the passed url string into a UrlBuilder.

static UrlBuilder parse(URL url)

Parse a UrlBuilder from the provided URL object.

UrlBuilder setHost(String host)

Set the host that will be used to build the final URL.

UrlBuilder setPath(String path)

Set the path that will be used to build the final URL.

UrlBuilder setPort(int port)

Set the port that will be used to build the final URL.

UrlBuilder setPort(String port)

Set the port that will be used to build the final URL.

UrlBuilder setQuery(String query)

Set the query that will be used to build the final URL.

UrlBuilder setQueryParameter(String queryParameterName, String queryParameterEncodedValue)

Set the provided query parameter name and encoded value to query string for the final URL.

UrlBuilder setScheme(String scheme)

Set the scheme/protocol that will be used to build the final URL.

String toString()

Get the string representation of the URL that is being built.

URL toUrl()

Get the URL that is being built.

Methods inherited from java.lang.Object

Constructor Details

UrlBuilder

public UrlBuilder()

Creates a new instance of UrlBuilder.

Method Details

addQueryParameter

public UrlBuilder addQueryParameter(String queryParameterName, String queryParameterEncodedValue)

Append the provided query parameter name and encoded value to query string for the final URL.

Parameters:

queryParameterName - The name of the query parameter.
queryParameterEncodedValue - The encoded value of the query parameter.

Returns:

The provided query parameter name and encoded value to query string for the final URL.

clearQuery

public UrlBuilder clearQuery()

Clear the query that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

getHost

public String getHost()

Get the host that has been assigned to this UrlBuilder.

Returns:

the host that has been assigned to this UrlBuilder.

getPath

public String getPath()

Get the path that has been assigned to this UrlBuilder.

Returns:

the path that has been assigned to this UrlBuilder.

getPort

public Integer getPort()

Get the port that has been assigned to this UrlBuilder.

Returns:

the port that has been assigned to this UrlBuilder.

getQuery

public Map<String,String> getQuery()

Get a view of the query that has been assigned to this UrlBuilder.

Changes to the Map returned by this API won't be reflected in the UrlBuilder.

Returns:

A view of the query that has been assigned to this UrlBuilder.

getQueryString

public String getQueryString()

Returns the query string currently configured in this UrlBuilder instance.

Returns:

A String containing the currently configured query string.

getScheme

public String getScheme()

Get the scheme/protocol that has been assigned to this UrlBuilder.

Returns:

the scheme/protocol that has been assigned to this UrlBuilder.

parse

public static UrlBuilder parse(String url)

Parses the passed url string into a UrlBuilder.

Parameters:

url - The URL string to parse.

Returns:

The UrlBuilder that was created from parsing the passed URL string.

parse

public static UrlBuilder parse(URL url)

Parse a UrlBuilder from the provided URL object.

Parameters:

url - The URL object to parse.

Returns:

The UrlBuilder that was parsed from the URL object.

setHost

public UrlBuilder setHost(String host)

Set the host that will be used to build the final URL.

Parameters:

host - The host that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

setPath

public UrlBuilder setPath(String path)

Set the path that will be used to build the final URL.

Parameters:

path - The path that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

setPort

public UrlBuilder setPort(int port)

Set the port that will be used to build the final URL.

Parameters:

port - The port that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

setPort

public UrlBuilder setPort(String port)

Set the port that will be used to build the final URL.

Parameters:

port - The port that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

setQuery

public UrlBuilder setQuery(String query)

Set the query that will be used to build the final URL.

Parameters:

query - The query that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

setQueryParameter

public UrlBuilder setQueryParameter(String queryParameterName, String queryParameterEncodedValue)

Set the provided query parameter name and encoded value to query string for the final URL.

Parameters:

queryParameterName - The name of the query parameter.
queryParameterEncodedValue - The encoded value of the query parameter.

Returns:

The provided query parameter name and encoded value to query string for the final URL.

setScheme

public UrlBuilder setScheme(String scheme)

Set the scheme/protocol that will be used to build the final URL.

Parameters:

scheme - The scheme/protocol that will be used to build the final URL.

Returns:

This UrlBuilder so that multiple setters can be chained together.

toString

public String toString()

Get the string representation of the URL that is being built.

Overrides:

UrlBuilder.toString()

Returns:

The string representation of the URL that is being built.

toUrl

public URL toUrl()

Get the URL that is being built.

Returns:

The URL that is being built.

Throws:

MalformedURLException

- if the URL is not fully formed.

Applies to