Constructs a URI using the specified URL. @param url the URL @param query the query @throws URISyntaxException If both a scheme and a path are given but the path is relative, if the URI string constructed from the given components violates RFC 2396, or if the a
(final URL url, final String query)
| 1318 | * @return the URI |
| 1319 | */ |
| 1320 | public static URI toURI(final URL url, final String query) throws URISyntaxException { |
| 1321 | final String scheme = url.getProtocol(); |
| 1322 | final String host = url.getHost(); |
| 1323 | final int port = url.getPort(); |
| 1324 | final String path = url.getPath(); |
| 1325 | final StringBuilder buffer = new StringBuilder(); |
| 1326 | if (host != null) { |
| 1327 | if (scheme != null) { |
| 1328 | buffer.append(scheme).append("://"); |
| 1329 | } |
| 1330 | buffer.append(host); |
| 1331 | if (port > 0) { |
| 1332 | buffer.append(':').append(port); |
| 1333 | } |
| 1334 | } |
| 1335 | if (path == null || path.isEmpty() || path.charAt(0) != '/') { |
| 1336 | buffer.append('/'); |
| 1337 | } |
| 1338 | if (path != null) { |
| 1339 | buffer.append(path); |
| 1340 | } |
| 1341 | if (query != null) { |
| 1342 | buffer.append('?').append(query); |
| 1343 | } |
| 1344 | return new URI(buffer.toString()); |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * @param part the part to encode |