fork download
  1. import java.net.URL;
  2. import java.net.MalformedURLException;
  3. import java.util.regex.Pattern;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. String uri = "https://p...content-available-to-author-only...e.com:25461/live/teste/1234/1224.m3u8";
  11.  
  12. /* Validação com a classe URL */
  13. try {
  14. new URL(uri);
  15.  
  16. System.out.println( uri.substring(uri.length() - 5) );
  17. } catch (MalformedURLException e) {
  18. System.out.println( "URL Inválida" );
  19. }
  20.  
  21. /* Trata o erro quando a string for menor que 5 caracteres */
  22. try {
  23. System.out.println( uri.substring(uri.length() - 5) );
  24. System.out.println( "O tamqanho da URL é inválido" );
  25. }
  26. }
  27. }
Success #stdin #stdout 0.04s 4575232KB
stdin
Standard input is empty
stdout
.m3u8
.m3u8