Java URI from toURI(CharSequence uriStr)

Here you can find the source of toURI(CharSequence uriStr)

Description

Creates a URI from the passed string

License

Apache License

Parameter

Parameter Description
uriStr A char sequence containing a URI representation

Return

a URI

Declaration

public static URI toURI(CharSequence uriStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.net.URI;

public class Main {
    /**//www .  j a  v  a2 s  .co m
     * Creates a URI from the passed string 
     * @param uriStr A char sequence containing a URI representation
     * @return a URI
     */
    public static URI toURI(CharSequence uriStr) {
        try {
            return new URI(nvl(uriStr, "Passed string was null").toString());
        } catch (Exception e) {
            throw new RuntimeException("Failed to create URL from string [" + uriStr + "]", e);
        }
    }

    public static <T> T nvl(T t, String message) {
        if (t == null)
            throw new IllegalArgumentException(message);
        return (T) t;
    }
}

Related

  1. toURI(File f)
  2. toUri(File folder)
  3. toURI(final java.io.File file, final StringBuilder builder)
  4. toURI(final String location)