< prev index next >

src/java.base/share/classes/java/net/URI.java

Print this page




 844 
 845     private static boolean validSchemeAndPath(String scheme, String path) {
 846         try {
 847             URI u = new URI(scheme + ":" + path);
 848             return scheme.equals(u.scheme) && path.equals(u.path);
 849         } catch (URISyntaxException e) {
 850             return false;
 851         }
 852     }
 853 
 854     /**
 855      * Creates a URI by parsing the given string.
 856      *
 857      * <p> This convenience factory method works as if by invoking the {@link
 858      * #URI(String)} constructor; any {@link URISyntaxException} thrown by the
 859      * constructor is caught and wrapped in a new {@link
 860      * IllegalArgumentException} object, which is then thrown.
 861      *
 862      * <p> This method is provided for use in situations where it is known that
 863      * the given string is a legal URI, for example for URI constants declared
 864      * within in a program, and so it would be considered a programming error
 865      * for the string not to parse as such.  The constructors, which throw
 866      * {@link URISyntaxException} directly, should be used situations where a
 867      * URI is being constructed from user input or from some other source that
 868      * may be prone to errors.  </p>
 869      *
 870      * @param  str   The string to be parsed into a URI
 871      * @return The new URI
 872      *
 873      * @throws  NullPointerException
 874      *          If {@code str} is {@code null}
 875      *
 876      * @throws  IllegalArgumentException
 877      *          If the given string violates RFC&nbsp;2396
 878      */
 879     public static URI create(String str) {
 880         try {
 881             return new URI(str);
 882         } catch (URISyntaxException x) {
 883             throw new IllegalArgumentException(x.getMessage(), x);
 884         }
 885     }
 886 




 844 
 845     private static boolean validSchemeAndPath(String scheme, String path) {
 846         try {
 847             URI u = new URI(scheme + ":" + path);
 848             return scheme.equals(u.scheme) && path.equals(u.path);
 849         } catch (URISyntaxException e) {
 850             return false;
 851         }
 852     }
 853 
 854     /**
 855      * Creates a URI by parsing the given string.
 856      *
 857      * <p> This convenience factory method works as if by invoking the {@link
 858      * #URI(String)} constructor; any {@link URISyntaxException} thrown by the
 859      * constructor is caught and wrapped in a new {@link
 860      * IllegalArgumentException} object, which is then thrown.
 861      *
 862      * <p> This method is provided for use in situations where it is known that
 863      * the given string is a legal URI, for example for URI constants declared
 864      * within a program, and so it would be considered a programming error
 865      * for the string not to parse as such.  The constructors, which throw
 866      * {@link URISyntaxException} directly, should be used in situations where a
 867      * URI is being constructed from user input or from some other source that
 868      * may be prone to errors.  </p>
 869      *
 870      * @param  str   The string to be parsed into a URI
 871      * @return The new URI
 872      *
 873      * @throws  NullPointerException
 874      *          If {@code str} is {@code null}
 875      *
 876      * @throws  IllegalArgumentException
 877      *          If the given string violates RFC&nbsp;2396
 878      */
 879     public static URI create(String str) {
 880         try {
 881             return new URI(str);
 882         } catch (URISyntaxException x) {
 883             throw new IllegalArgumentException(x.getMessage(), x);
 884         }
 885     }
 886 


< prev index next >