Created
August 24, 2016 17:28
-
-
Save maoueh/c9b4f5d866c594106f3818e7ea0b7c93 to your computer and use it in GitHub Desktop.
Simple Uris Java helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.URI; | |
import java.net.URISyntaxException; | |
/** | |
* Unlicense granted <http://unlicense.org> | |
*/ | |
public final class Uris { | |
/** | |
* An unchecked version of the {@link URI#URI(String)} construction, i.e. a version that does not throw {@link | |
* URISyntaxException}. Instead, this method wraps the checked {@link URISyntaxException} into an unchecked {@link | |
* IllegalArgumentException}. | |
* | |
* @param value The value to convert to an {@link URI}. | |
* @return The {@link URI} represented by the String. | |
* @throws IllegalArgumentException When the value is not a valid parseable {@link URI}. | |
*/ | |
public static URI create(String value) { | |
try { | |
return new URI(value); | |
} catch (URISyntaxException exception) { | |
throw new IllegalArgumentException(exception); | |
} | |
} | |
private Uris() { | |
// Prevent instantiation | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment