Java Utililty Methods URI Create

List of utility methods to do URI Create

Description

The list of methods to do URI Create are organized into topic(s).

Method

InetSocketAddressgetURIAddress(URI uri)
get URI Address
String host = uri.getHost();
int port = uri.getPort();
return new InetSocketAddress(host, port);
URIgetUriByEndpoint(String endpoint)
Get the URI object for the given endpoint.
URI targetEndpointUri = null;
try {
    targetEndpointUri = new URI(endpoint);
    if (targetEndpointUri.getHost() == null) {
        targetEndpointUri = new URI("http://" + endpoint);
} catch (URISyntaxException e) {
    throw new RuntimeException("Unable to parse service endpoint: " + e.getMessage());
...
StringgetURIFilename(final String s)
Get the filename of an URI
if (s == null) {
    return null;
try {
    final URI uri = new URI(s);
    return new File(uri.getPath()).getName();
} catch (URISyntaxException e) {
    return null;
...
URIgetURIFromEncodedString(String unencoded)
get URI From Encoded String
URI uri;
String[] split = unencoded.split("\\?");
String part1 = split[0].replaceAll("\\[", URLEncoder.encode("[", "UTF8"))
        .replaceAll("\\]", URLEncoder.encode("]", "UTF8"))
        .replaceAll("\\|", URLEncoder.encode("|", "UTF8"));
if (split.length < 2) {
    uri = new URI(part1);
} else {
...
URIgetURIFromPath(String fileOrURI)
Get a URI from a string.
URI uri = null;
try {
    uri = new URI(fileOrURI);
    if (uri.getScheme() == null) {
        uri = new File(fileOrURI).toURI();
} catch (URISyntaxException usx) {
    uri = new File(fileOrURI).toURI();
...
URIgetURIFromPath(String path)
get URI From Path
URI retUri = null;
try {
    retUri = new URI(path);
} catch (URISyntaxException e) {
    e.printStackTrace();
return retUri;
StringgetURIName(String forwardSlashPath)
Path is parsed using '/' as separator.
if (forwardSlashPath == null)
    return null;
int end = forwardSlashPath.length();
if (end == 0)
    return "";
if (forwardSlashPath.charAt(end - 1) == '/')
    end = end - 1;
if (end == 0)
...
StringgetURIName(URI uri)
get URI Name
File file = new File(uri.getPath());
return file.getName();
StringgetURIParameterValue(URI uri, String name, String defVal)
get URI Parameter Value
if (uri == null || name == null)
    return defVal;
final String rawQuery = uri.getRawQuery();
if (rawQuery == null)
    return defVal;
String part;
int s = 0;
int e = rawQuery.indexOf('&');
...
URI[]getURIs(final Object[] objs)
ottengo un array di URI da un array contenente File o URL
final List<URI> uris = new LinkedList<URI>();
for (final Object obj : objs) {
    if (obj instanceof URI) {
        uris.add((URI) obj);
    } else if (obj instanceof URL) {
        uris.add(((URL) obj).toURI());
    } else if (obj instanceof File) {
        uris.add(((File) obj).toURI());
...