Пример #1
29
 /** Check if an URL is relative to another URL. */
 public static boolean relativeURL(URL url1, URL url2) {
   return ((url1.getProtocol() == null && url2.getProtocol() == null)
           || url1.getProtocol().equals(url2.getProtocol()))
       && ((url1.getAuthority() == null && url2.getAuthority() == null)
           || url1.getAuthority().equals(url2.getAuthority()))
       && ((url1.getPath() == null && url2.getPath() == null)
           || url2.getPath().startsWith(url1.getPath()));
 }
Пример #2
0
 /**
  * Get the last modification date of a URL.
  *
  * @return last modified timestamp "as is"
  */
 public static long getLastModified(URL url) throws IOException {
   if ("file".equals(url.getProtocol())) {
     // Optimize file: access. Also, this prevents throwing an exception if the file doesn't exist
     // as we try to close the stream below.
     return new File(URLDecoder.decode(url.getFile(), STANDARD_PARAMETER_ENCODING)).lastModified();
   } else {
     // Use URLConnection
     final URLConnection urlConnection = url.openConnection();
     if (urlConnection instanceof HttpURLConnection)
       ((HttpURLConnection) urlConnection).setRequestMethod("HEAD");
     try {
       return getLastModified(urlConnection);
     } finally {
       final InputStream is = urlConnection.getInputStream();
       if (is != null) is.close();
     }
   }
 }