Skip to content

Instantly share code, notes, and snippets.

@maoueh
Created August 24, 2016 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maoueh/c9b4f5d866c594106f3818e7ea0b7c93 to your computer and use it in GitHub Desktop.
Save maoueh/c9b4f5d866c594106f3818e7ea0b7c93 to your computer and use it in GitHub Desktop.
Simple Uris Java helper
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