Skip to content

Instantly share code, notes, and snippets.

@jonatasemidio
Created November 1, 2014 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonatasemidio/a4096090704ddcea2ee4 to your computer and use it in GitHub Desktop.
Save jonatasemidio/a4096090704ddcea2ee4 to your computer and use it in GitHub Desktop.
OBS: Código testaro na versão Javac 1.7.0_09
class UrlProcessor{
public void detalhamentoUrl(String site){
try{
if(site.substring(0, 3).equals("htt")){
java.net.URL url = new java.net.URL(site);
String path = url.toURI().getPath().substring(1, url.getPath().length());
System.out.println("protocolo: "+url.getProtocol());
System.out.println("host: "+url.getHost().substring(0,3));
System.out.println("domínio: "+url.getHost().substring(4, url.getHost().length()));
System.out.println("path: "+path.split("/")[0]);
System.out.println("parâmetros: "+path.split("/")[1]);
System.out.println("--------");
}else{
System.out.println(site.substring(0, 3));
System.out.println(site.split("://")[1].split("%")[0]);
System.out.println(site.split("%")[1].split("@")[0]);
System.out.println(site.split("@")[1]);
System.out.println("--------");
}
}catch(java.io.IOException e){
e.getMessage();
}catch(java.net.URISyntaxException e ){
e.getMessage();
}catch(Exception e){System.out.println("URL inválida!");}
}
public static void main(String[] args){
UrlProcessor processor = new UrlProcessor();
processor.detalhamentoUrl("http://www.google.com/mail/user=fulano");
processor.detalhamentoUrl("ssh://fulano%senha@git.com/");
processor.detalhamentoUrl("13h23u4gu2yq3g4q");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment