Here you can find the source of uri(String uriStr)
String
into a URI
.
Parameter | Description |
---|---|
uriStr | The String to be converted or <code>null</code>. |
Parameter | Description |
---|---|
IllegalArgumentException | if the String could not be converted. |
null
if null
was passed, otherwise the corresponding URI.
public static URI uri(String uriStr)
//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$ } } }