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

StringgetUriScheme(String address)
get Uri Scheme
try {
    URI addrURI = new URI(address);
    String scheme = addrURI.getScheme();
    return scheme != null ? scheme : HTTP;
} catch (URISyntaxException e) {
    return HTTP;
StringgetURIsPrettyPrint(final Collection uris)
Returns a string describing of a collection of URI objects.
final StringBuilder builder = new StringBuilder(uris.size() << 4).append("[ ");
for (URI uri : uris)
    builder.append(uri.getFragment()).append(", ");
builder.replace(builder.length() - 2, builder.length(), " ]");
return builder.toString();
InputStreamgetURIStream(Object obj)
get URI Stream
if (obj instanceof File) {
    return new BufferedInputStream(new FileInputStream((File) obj));
else if (obj instanceof URI) {
    return ((URI) obj).toURL().openStream();
return null;
URIgetURIWithAuthority(URI uri, String authority)
Converts URI to a URI with the given authority.
try {
    if (uri.getScheme() == null)
        return new URI("file", uri.getPath(), null); 
    if ("gitfs".equals(uri.getScheme())) 
        return new URI(uri.getScheme(), authority, uri.getPath(), uri.getQuery(), uri.getFragment());
    return uri;
} catch (URISyntaxException e) {
    e.printStackTrace();
...
URIstringToUri(String fileString)
string To Uri
return new File(fileString).toURI();
URI[]stringToURI(String[] str)
string To URI
if (str == null)
    return null;
URI[] uris = new URI[str.length];
for (int i = 0; i < str.length; i++) {
    try {
        uris[i] = new URI(str[i]);
    } catch (URISyntaxException ur) {
        throw new IllegalArgumentException("Failed to create uri for " + str[i], ur);
...
URIuri(String host, String prefix, String path)
uri
String name = host;
int port = 80;
int index = host.indexOf(':');
if (index > 0) {
    String[] split = host.split(":");
    name = split[0];
    port = Integer.valueOf(split[1]);
return new URI("http", null, name, port, prefix + "/" + path, null, null);
URIuri(String path)
uri
return new URI("http", null, HOST, PORT, path, null, null);
URIuri(String str)
uri
try {
    return new URI(str);
} catch (URISyntaxException e) {
    throw new IllegalArgumentException(e);
URIuri(String uri)
uri
try {
    return new URI(uri);
} catch (RuntimeException e) {
    throw e;
} catch (Exception e) {
    throw new RuntimeException(e.getMessage(), e);