Java Utililty Methods URI from

List of utility methods to do URI from

Description

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

Method

URItoURI(String sUri)
to URI
try {
    return new URI(sUri);
} catch (URISyntaxException e) {
    return null;
URItoURI(String uri)
to URI
if (uri == null)
    return null;
return URI.create(uri);
URItoUri(String uri)
to Uri
return new URI(uri.replace(" ", "%20"));
URItoURI(String uri)
Converts a string to a URI without a URISyntaxException
try {
    return new URI(uri);
} catch (URISyntaxException e) {
    throw new RuntimeException(e);
URItoURI(URI parent, String child)
Convenient method to simulate a parent/child composition
try {
    if (parent == null) {
        throw new IllegalArgumentException("Parent is null");
    StringBuilder dirName = new StringBuilder(parent.toString());
    if (dirName.charAt(dirName.length() - 1) != '/') {
        dirName.append('/');
    if ((child == null) || child.isEmpty()) {
        throw new IllegalArgumentException("Child is null or empty");
    if (child.startsWith("/")) {
        throw new IllegalArgumentException("Child is absolute: " + child);
    return new URI(dirName.append(child).toString());
} catch (URISyntaxException ex) {
    throw new IllegalArgumentException(ex.getMessage(), ex);
URI[]toURIArray(String[] array)
Convert an array of strings into an array of URI instances.
URI[] uris = new URI[array.length];
for (int i = 0; i < array.length; i++) {
    uris[i] = URI.create(array[i].trim());
return uris;
ListtoURIList(Collection stringList)
to URI List
List<URI> uriList = null;
if (stringList != null && !stringList.isEmpty()) {
    uriList = new ArrayList<>();
    for (String uriStr : stringList) {
        uriList.add(URI.create(uriStr));
return uriList;
...
URItoURIObject(String uri)
to URI Object
try {
    return new URI(uri);
} catch (URISyntaxException e) {
    throw new IOException("Could not parse uri: " + uri + " - " + e.getMessage());
URI[]toURIs(File... files)
Convert files to URI in correct way.
URI[] uris = new URI[files.length];
for (int i = 0; i < uris.length; i++) {
    uris[i] = files[i].toURI();
return uris;
ListtoURIs(Iterable files)
to UR Is
List<URI> urls = new ArrayList<URI>();
for (File file : files) {
    urls.add(file.toURI());
return urls;