public class URLBuilder extends Object
The major advantage is to be able to add parameters without caring if a '?' or a '&' has to be used.
Modifier and Type | Field and Description |
---|---|
static String |
PROTOCOL_HTTP
Can be used to specify the HTTP protocol in
URLBuilder(String, String) . |
static String |
PROTOCOL_HTTPS
Can be used to specify the HTTPS protocol in
URLBuilder(String, String) . |
Constructor and Description |
---|
URLBuilder(String baseURL)
Creates a new instance pre filled with the given baseURL.
|
URLBuilder(String protocol,
String host)
Creates a new instance targeting the given host using the given protocol.
|
Modifier and Type | Method and Description |
---|---|
URLBuilder |
addParameter(String key,
Object value)
Adds a parameter to the url.
|
URLBuilder |
addParameter(String key,
Object value,
boolean urlEncode)
Adds a parameter to the url.
|
URLBuilder |
addPart(String... uriPartsToAdd)
Adds a path part to the url.
|
String |
toString() |
public static final String PROTOCOL_HTTP
URLBuilder(String, String)
.public static final String PROTOCOL_HTTPS
URLBuilder(String, String)
.public URLBuilder(@Nonnull String baseURL)
baseURL
- the base url to stat with in a form like http://somehost.compublic URLBuilder addPart(@Nonnull String... uriPartsToAdd)
Once the first parameter has been added, the path can no longer be modified.
uriPartsToAdd
- the uri part to add. This should not contain a leading '/' as it is added automatically. If
an array (vararg) is given, all components are appended to the internal StringBuilder
without any additional characters.public URLBuilder addParameter(@Nonnull String key, @Nullable Object value)
key
- the name of the parametervalue
- the value of the parameter which will be url encoded. If the given value is null an empty
parameter will be added.public URLBuilder addParameter(@Nonnull String key, @Nullable Object value, boolean urlEncode)
key
- the name of the parametervalue
- the value of the parameter . If the given value is null an empty parameter will be added.urlEncode
- true if the given value should be url encoded before addingCopyright © 2018. All rights reserved.