fork download
  1. import java.net.URI;
  2. import java.net.URISyntaxException;
  3.  
  4. class Ideone {
  5.  
  6. public static void main(String[] args) {
  7. String problemUrl = "http:///1.1.1.1:8001";
  8.  
  9. try {
  10. URI uriProblem = new URI(problemUrl);
  11. System.out.println("Three slash");
  12. System.out.println("Host is: " + uriProblem.getHost());
  13. System.out.println("Path is: " + uriProblem.getPath());
  14.  
  15. } catch (URISyntaxException e) {
  16. System.out.println("Caught Exception: " + e.getMessage());
  17. System.out.println("Result: Fails validation.");
  18. }
  19.  
  20. System.out.println("\n----------------------------------\n");
  21.  
  22. String correctUrl = "http://1.1.1.1:8001";
  23.  
  24. try {
  25. URI uriCorrect = new URI(correctUrl);
  26.  
  27. System.out.println("Two slash");
  28. System.out.println("Host is: " + uriCorrect.getHost());
  29. System.out.println("Path is: " + uriCorrect.getPath());
  30.  
  31. } catch (URISyntaxException e) {
  32. System.out.println("Exception: " + e.getMessage());
  33. }
  34. }
  35. }
Success #stdin #stdout 0.14s 57648KB
stdin
Standard input is empty
stdout
Three slash
Host is: null
Path is: /1.1.1.1:8001

----------------------------------

Two slash
Host is: 1.1.1.1
Path is: