Utility method - set the part, ensuring valid format. If encode=true, then some elements will be run through the encoder (path, userinfo, query, fragment), otherwise the elements will be validated for proper encoding.
(String newAuthority, boolean encode)
| 295 | * encoding. |
| 296 | */ |
| 297 | protected void setAuthority(String newAuthority, boolean encode) throws URISyntaxException { |
| 298 | if ((this.authority = newAuthority) == null) { |
| 299 | return; |
| 300 | } |
| 301 | if (authority.startsWith(AUTHORITY_MARKER)) { |
| 302 | authority = authority.substring(AUTHORITY_MARKER.length()); |
| 303 | newAuthority = authority; |
| 304 | } |
| 305 | int index = newAuthority.indexOf(USERINFO_SEPARATOR); |
| 306 | if (index != -1) { |
| 307 | this.userInfo = newAuthority.substring(0, index); |
| 308 | if (encode) { |
| 309 | this.userInfo = URIHelper.encodeString(this.userInfo); |
| 310 | } else { |
| 311 | // validate |
| 312 | URIHelper.decodeString(this.userInfo); |
| 313 | } |
| 314 | newAuthority = newAuthority.substring(index + 1); |
| 315 | } |
| 316 | index = newAuthority.indexOf(PORT_SEPARATOR); |
| 317 | if (index == 0) { |
| 318 | this.host = null; |
| 319 | this.port = parseIntOption("port", newAuthority.substring(1)); |
| 320 | } else if (index == -1) { |
| 321 | this.host = newAuthority; |
| 322 | this.port = -1; |
| 323 | } else { |
| 324 | this.host = newAuthority.substring(0, index); |
| 325 | this.port = parseIntOption("port", newAuthority.substring(index + 1)); |
| 326 | } |
| 327 | if (encode == true) { |
| 328 | // to reconstruct the authority with the encoded value |
| 329 | setAuthority(host, port, userInfo, false); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /** |
| 334 | * Utility method to set the query. If parameter encode=true, then the |
no test coverage detected