Created
November 1, 2014 01:42
-
-
Save jonatasemidio/a4096090704ddcea2ee4 to your computer and use it in GitHub Desktop.
OBS: Código testaro na versão Javac 1.7.0_09
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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