determine the host, port and userinfo if the authority parses successfully to a server based authority behavour in error cases: if forceServer is true, throw URISyntaxException with the proper diagnostic messages. if forceServer is false assume this is a registry based uri, and just return leaving
(boolean forceServer)
| 482 | * regardless of the forceServer parameter e.g. malformed ipv6 address |
| 483 | */ |
| 484 | private void parseAuthority(boolean forceServer) |
| 485 | throws URISyntaxException { |
| 486 | if (authority == null) { |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | String temp, tempUserinfo = null, tempHost = null; |
| 491 | int index, hostindex = 0; |
| 492 | int tempPort = -1; |
| 493 | |
| 494 | temp = authority; |
| 495 | index = temp.indexOf('@'); |
| 496 | if (index != -1) { |
| 497 | // remove user info |
| 498 | tempUserinfo = temp.substring(0, index); |
| 499 | validateUserinfo(authority, tempUserinfo, 0); |
| 500 | temp = temp.substring(index + 1); // host[:port] is left |
| 501 | hostindex = index + 1; |
| 502 | } |
| 503 | |
| 504 | index = temp.lastIndexOf(':'); |
| 505 | int endindex = temp.indexOf(']'); |
| 506 | |
| 507 | if (index != -1 && endindex < index) { |
| 508 | // determine port and host |
| 509 | tempHost = temp.substring(0, index); |
| 510 | |
| 511 | if (index < (temp.length() - 1)) { // port part is not empty |
| 512 | try { |
| 513 | tempPort = Integer.parseInt(temp.substring(index + 1)); |
| 514 | if (tempPort < 0) { |
| 515 | if (forceServer) { |
| 516 | throw new URISyntaxException( |
| 517 | authority, |
| 518 | Messages.getString("luni.8B"), hostindex + index + 1); //$NON-NLS-1$ |
| 519 | } |
| 520 | return; |
| 521 | } |
| 522 | } catch (NumberFormatException e) { |
| 523 | if (forceServer) { |
| 524 | throw new URISyntaxException(authority, Messages |
| 525 | .getString("luni.8B"), hostindex + index + 1); //$NON-NLS-1$ |
| 526 | } |
| 527 | return; |
| 528 | } |
| 529 | } |
| 530 | } else { |
| 531 | tempHost = temp; |
| 532 | } |
| 533 | |
| 534 | if (tempHost.equals("")) { //$NON-NLS-1$ |
| 535 | if (forceServer) { |
| 536 | throw new URISyntaxException(authority, Messages |
| 537 | .getString("luni.A0"), hostindex); //$NON-NLS-1$ |
| 538 | } |
| 539 | return; |
| 540 | } |
| 541 |
no test coverage detected