updated getLastModified() to support the file:// protocol

Former-commit-id: 75604221f3e38de0c877fa6e8b5048da593a2a56
This commit is contained in:
Jeremy Long
2013-08-03 12:09:44 -04:00
parent 92a8357690
commit 7365214fb6

View File

@@ -27,6 +27,7 @@ import java.net.HttpURLConnection;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@@ -162,7 +163,8 @@ public final class Downloader {
/** /**
* Makes an HTTP Head request to retrieve the last modified date of the * Makes an HTTP Head request to retrieve the last modified date of the
* given URL. * given URL. If the file:// protocol is specified, then the lastTimestamp
* of the file is returned.
* *
* @param url the URL to retrieve the timestamp from * @param url the URL to retrieve the timestamp from
* @return an epoch timestamp * @return an epoch timestamp
@@ -170,8 +172,19 @@ public final class Downloader {
* the HTTP request * the HTTP request
*/ */
public static long getLastModified(URL url) throws DownloadFailedException { public static long getLastModified(URL url) throws DownloadFailedException {
HttpURLConnection conn = null;
long timestamp = 0; long timestamp = 0;
//TODO add the FPR protocol?
if ("file:".equalsIgnoreCase(url.getProtocol())) {
File f;
try {
f = new File(url.toURI());
} catch (URISyntaxException ex) {
final String msg = String.format("Unable to locate '%s'; is the cve.url-2.0.modified property set correctly?", url.toString());
throw new DownloadFailedException(msg);
}
timestamp = f.lastModified();
} else {
HttpURLConnection conn = null;
try { try {
conn = Downloader.getConnection(url); conn = Downloader.getConnection(url);
conn.setRequestMethod("HEAD"); conn.setRequestMethod("HEAD");
@@ -188,6 +201,7 @@ public final class Downloader {
} }
} }
} }
}
return timestamp; return timestamp;
} }