class UriUtils {

    public static URI buildSafeUri(String scheme,
                                   String userInfo, String host, int port,
                                   String path, String query, String fragment)
            throws URISyntaxException {
        try {
            return new URI(scheme, userInfo, host, port, path, query, fragment);
        } catch (URISyntaxException e) {
            String encodedInput = URLEncode(e.getInput());
            throw new URISyntaxException(encodedInput, e.getReason());
        }
    }

    private  UriUtils();

}