@Test public void validUrlsThatDoNotExistShouldWork() throws Exception { final UrlResource urlResource = new UrlResource("http: assertFalse(urlResource.exists()); }
@Override public boolean exists() { try { HttpURLConnection.setFollowRedirects(true); HttpURLConnection con = (HttpURLConnection) new URL(path).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); return (responseCode == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } }
UrlResource extends Resource { @Override public boolean exists() { try { HttpURLConnection.setFollowRedirects(true); HttpURLConnection con = (HttpURLConnection) new URL(path).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); return (responseCode == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } } }
UrlResource extends Resource { @Override public boolean exists() { try { HttpURLConnection.setFollowRedirects(true); HttpURLConnection con = (HttpURLConnection) new URL(path).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); return (responseCode == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } } UrlResource(String path); }
UrlResource extends Resource { @Override public boolean exists() { try { HttpURLConnection.setFollowRedirects(true); HttpURLConnection con = (HttpURLConnection) new URL(path).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); return (responseCode == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } } UrlResource(String path); @Override boolean exists(); @Override InputStream getInputStream(); }
UrlResource extends Resource { @Override public boolean exists() { try { HttpURLConnection.setFollowRedirects(true); HttpURLConnection con = (HttpURLConnection) new URL(path).openConnection(); con.setRequestMethod("HEAD"); int responseCode = con.getResponseCode(); return (responseCode == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } } UrlResource(String path); @Override boolean exists(); @Override InputStream getInputStream();  }