Skip to content

Instantly share code, notes, and snippets.

@DavyLandman
Created September 23, 2012 15:41
Show Gist options
  • Save DavyLandman/3772075 to your computer and use it in GitHub Desktop.
Save DavyLandman/3772075 to your computer and use it in GitHub Desktop.
URI encoding stuff in Java
project://name/path
auth: name host: name port: -1
project://name%20space/path
auth: name space host: null port: -1
project://name:200/path
auth: name:200 host: name port: 200
project://name%20space:200/path
auth: name space:200 host: null port: -1
private static void printInfo(URI u) {
System.out.println(u.toString());
System.out.printf("\tauth: %-20s host: %-20s port: %d\n\n", u.getAuthority(), u.getHost(), u.getPort());
}
public static void main(String[] args) throws URISyntaxException {
printInfo(new URI("project","name","/path", null, null));
printInfo(new URI("project","name space","/path", null, null));
printInfo(new URI("project","name:200","/path", null, null));
printInfo(new URI("project","name space:200","/path", null, null));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment