Here you can find the source of isValidUri(String uri, StringBuilder errMsg)
Parameter | Description |
---|---|
uri | The string to be tested. |
errMsg | On false, will be populated with brief failure description. |
static public boolean isValidUri(String uri, StringBuilder errMsg)
//package com.java2s; /*/* w w w . j a va 2 s . co m*/ * IRIS -- Intelligent Roadway Information System * Copyright (C) 2014-2015 AHMCT, University of California * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ import java.net.URI; import java.net.URISyntaxException; public class Main { /** * Tests whether the given URI matches RFC-2396 specs. * @param uri The string to be tested. * @param errMsg On false, will be populated with brief failure description. * @return Whether the given string is a valid URI. */ static public boolean isValidUri(String uri, StringBuilder errMsg) { boolean ret = true; if (uri == null) { if (errMsg != null) { errMsg.append("URI is null"); } ret = false; } else { try { new URI(uri); } catch (URISyntaxException se) { ret = false; if (errMsg != null) { errMsg.append(se.getMessage()); } } } return ret; } /** * Tests whether the given URI matches RFC-3986 specs. * @param uri The string to be tested. * @return Whether the given string is a valid URI. */ static public boolean isValidUri(String uri) { return isValidUri(uri, null); } }