@Nullable
    public static URI getUriWithScheme(@Nullable final URI uri, final String scheme) {
        if (uri == null) {
            return null;
        }

        try {
            return new URI(
                    scheme,
                    uri.getUserInfo(),
                    uri.getHost(),
                    uri.getPort(),
                    uri.getPath(),
                    uri.getQuery(),
                    uri.getFragment());
        } catch (URISyntaxException e) {
            throw new RuntimeException("Could not parse URI.", e);
        }
    }
@Test
    public void testGetUriWithScheme() throws Exception {
        assertEquals("gopher", Tools.getUriWithScheme(new URI("http://example.com"), "gopher").getScheme());
        assertNull(Tools.getUriWithScheme(new URI("http://example.com"), null).getScheme());
        assertNull(Tools.getUriWithScheme(null, "http"));
    }