Java URI Create uri(String uriStr)

Here you can find the source of uri(String uriStr)

Description

Convert an String into a URI.

License

Open Source License

Parameter

Parameter Description
uriStr The String to be converted or <code>null</code>.

Exception

Parameter Description
IllegalArgumentException if the String could not be converted.

Return

null if null was passed, otherwise the corresponding URI.

Declaration

public static URI uri(String uriStr) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text of
 * such license is available at www.eclipse.org.
 *****************************************************************************/

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class Main {
    /**/*from   w w  w  .  ja  v  a 2  s  . co m*/
     * Convert an <code>String</code> into a <code>URI</code>.
     * 
     * @param uriStr
     *            The String to be converted or <code>null</code>.
     * @return <code>null</code> if <code>null</code> was passed, otherwise the
     *         corresponding URI.
     * @throws IllegalArgumentException
     *             if the String could not be converted.
     */
    public static URI uri(String uriStr) {
        try {
            return uriStr == null ? null : new URI(uriStr);
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Unable to convert String into URI: " + uriStr); //$NON-NLS-1$
        }
    }

    /**
     * Convert an <code>URL</code> into a <code>URI</code>.
     * 
     * @param url
     *            The url to be converted or <code>null</code>.
     * @return <code>null</code> if <code>null</code> was passed, otherwise the
     *         corresponding URI.
     * @throws IllegalArgumentException
     *             if the URL could not be converted.
     */
    public static URI uri(URL url) {
        try {
            return url == null ? null : url.toURI();
        } catch (URISyntaxException e) {
            throw new IllegalArgumentException("Unable to convert URL into URI: " + url); //$NON-NLS-1$
        }
    }
}

Related

  1. uri(String host, String prefix, String path)
  2. uri(String path)
  3. uri(String str)
  4. uri(String uri)
  5. uri(String uri)
  6. uri(String value)
  7. uri(String value)
  8. uri(URI uri)