Java Utililty Methods URL Value Check

List of utility methods to do URL Value Check

Description

The list of methods to do URL Value Check are organized into topic(s).

Method

booleanisLocalFile(URL url)
is Local File
try {
    if (url.getProtocol().equals(new File(url.getFile()).toURI().toURL().getProtocol())) {
        return true;
} catch (Throwable throwable) {
    throwable.printStackTrace();
return false;
...
booleanisLocalFile(URL url)
is Local File
return url.toExternalForm().toLowerCase().startsWith("file:");
booleanisLocalhost(URL url)
Checks whether the given URL is a localhost address
try {
    InetAddress address = InetAddress.getByName(url.getHost());
    if (address.isAnyLocalAddress() || address.isLoopbackAddress()) {
        return true;
    try {
        return NetworkInterface.getByInetAddress(address) != null;
    } catch (SocketException e) {
...
booleanisLocalURL(String s)
is Local URL
return s != null && s.startsWith("http://localboard/");
booleanisLocalURL(URL url)
is Local URL
String proto = url.getProtocol();
if (proto.equals("jar") || proto.equals("reference")) 
    String spec = url.getFile();
    int sepIdx = spec.indexOf(':');
    if (sepIdx == -1)
        return false;
    proto = spec.substring(0, sepIdx);
...
booleanisLocalURL(URL url)
Whether or not it's a file url.
return url.toString().startsWith("file:");
booleanisNewer(URL file, URL reference)
is Newer
if (file == null || reference == null)
    throw new IllegalArgumentException("null file value");
file = getFileURL(file);
reference = getFileURL(reference);
if (!isFile(file) && !isFile(reference))
    throw new IllegalArgumentException("destination is not a file URL");
long fileLastModified = 0;
long referenceLastModified = 0;
...
booleanisResponseCode(String url, int expectedCode)
is Response Code
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestMethod("GET");
connection.connect();
return connection.getResponseCode() == expectedCode;
booleanisResponsive(URL url)
is Responsive
try {
    HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection();
    httpConnection.setRequestMethod("HEAD");
    httpConnection.setConnectTimeout(1000);
    httpConnection.setReadTimeout(1000);
    return httpConnection.getResponseCode() == 200;
} catch (IOException ioe) {
    return false;
...
booleanisSameFile(URL u, File out)
is Same File
try {
    if (u == null || out == null)
        return false;
    return out.equals(new File(u.toURI()));
} catch (Throwable e) {
    return false;