Refine search
private java.util.Date timeFromDateHeaderField(URL url) { URLConnection urlConn; try { urlConn = url.openConnection(); return new Date(urlConn.getLastModified()); } catch (IOException ie) { return new java.util.Date(0); } }
public void doIndex( StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { URLConnection con = connect(); // since we end up redirecting users to jnlpJars/foo.jar/, set the content disposition // so that browsers can download them in the right file name. // see http://support.microsoft.com/kb/260519 and http://www.boutell.com/newfaq/creating/forcedownload.html rsp.setHeader("Content-Disposition", "attachment; filename=" + fileName); InputStream in = con.getInputStream(); rsp.serveFile(req, in, con.getLastModified(), con.getContentLength(), "*.jar" ); in.close(); }
/** * Retrieve the last modified date/time of a URL. * @param url the URL * @return the last modified date/time */ public static long getLastModified(URL url) { try { URLConnection conn = url.openConnection(); try { return conn.getLastModified(); } finally { //An InputStream is created even if it's not accessed, but we need to close it. IOUtils.closeQuietly(conn.getInputStream()); } } catch (IOException e) { // Should never happen, because URL must be local log.debug("IOError: " + e.getMessage()); return 0; } }
conn = url.openConnection(); int hash = classpath.hashCode() ^ (int) conn.getLastModified(); return hash; } catch (IOException ex) { if (conn != null) { try { conn.getInputStream().close(); conn.getOutputStream().close(); } catch (IOException ex) { }
URLConnection uc = url.openConnection(); return uc.getLastModified();
long sourceTimestamp = con.getLastModified(); InputStream in = archive.getProtocol().startsWith("http") ? ProxyConfiguration.getInputStream(archive) : con.getInputStream(); CountingInputStream cis = new CountingInputStream(in); try {
private static Supplier attr(final URL resource, final BiConsumer<Long, Long> attrs) throws Exception { if ("file".equals(resource.getProtocol())) { File file = new File(resource.toURI()); if (file.exists() && file.isFile()) { attrs.accept(file.length(), file.lastModified()); return () -> new FileInputStream(file); } return null; } else { URLConnection cnn = resource.openConnection(); cnn.setUseCaches(false); attrs.accept(cnn.getContentLengthLong(), cnn.getLastModified()); try { Closeables.closeQuietly(cnn.getInputStream()); } catch (NullPointerException ex) { // dir entries throw NPE :S return null; } return () -> resource.openStream(); } }
/** * Returns the time-stamp for a document's last update */ private final long getLastModified(String uri) { try { URL url = new URL(uri); URLConnection connection = url.openConnection(); long timestamp = connection.getLastModified(); // Check for a "file:" URI (courtesy of Brian Ewins) if (timestamp == 0){ // get 0 for local URI if ("file".equals(url.getProtocol())){ File localfile = new File(URLDecoder.decode(url.getFile())); timestamp = localfile.lastModified(); } } return(timestamp); } // Brutal handling of all exceptions catch (Exception e) { return(System.currentTimeMillis()); } }
public InputStream openStream() { try { final URLConnection connection = getConnection(); this.lastModified = connection.getLastModified(); return connection.getInputStream(); } catch (IOException e) { throw Util.newInternal( e, "Error while opening properties file '" + url + "'"); } }
jarConn = jarURL.openConnection(); return jarConn.getLastModified(); } catch (IOException e) { return -1; } finally { try { if (jarConn != null) jarConn.getInputStream().close(); } catch (IOException e) { } long lastModified = conn.getLastModified(); if (lastModified == -1L && url.getProtocol().equals("file")) {
@Override public HttpFileAttributes readAttributes() throws IOException { if (attrs == null) { final URLConnection conn = url.openConnection(); final long length = conn.getContentLengthLong(); final long lastModifiedMillis = conn.getLastModified(); attrs = new HttpFileAttributes(length, lastModifiedMillis); } return attrs; }
public void doIndex( StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { URLConnection con = connect(); // since we end up redirecting users to jnlpJars/foo.jar/, set the content disposition // so that browsers can download them in the right file name. // see http://support.microsoft.com/kb/260519 and http://www.boutell.com/newfaq/creating/forcedownload.html rsp.setHeader("Content-Disposition", "attachment; filename=" + fileName); InputStream in = con.getInputStream(); rsp.serveFile(req, in, con.getLastModified(), con.getContentLength(), "*.jar" ); in.close(); }
case "jar": try { final JarURLConnection jarConnection = (JarURLConnection) resourceURL.openConnection(); final JarEntry entry = jarConnection.getJarEntry(); return entry.getTime(); URLConnection connection = null; try { connection = resourceURL.openConnection(); return connection.getLastModified(); } catch (IOException ignored) { return 0; if (connection != null) { try { connection.getInputStream().close(); } catch (IOException ignored) {
@Override public long lastModified() throws IOException { URL url = getURL(); boolean fileCheck = false; if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) { // Proceed with file system resolution fileCheck = true; try { File fileToCheck = getFileForLastModifiedCheck(); long lastModified = fileToCheck.lastModified(); if (lastModified > 0L || fileToCheck.exists()) { return lastModified; } } catch (FileNotFoundException ex) { // Defensively fall back to URL connection check instead } } // Try a URL connection last-modified header URLConnection con = url.openConnection(); customizeConnection(con); long lastModified = con.getLastModified(); if (fileCheck && lastModified == 0 && con.getContentLengthLong() <= 0) { throw new FileNotFoundException(getDescription() + " cannot be resolved in the file system for checking its last-modified timestamp"); } return lastModified; }
public void doIndex( StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { URLConnection con = connect(); // since we end up redirecting users to jnlpJars/foo.jar/, set the content disposition // so that browsers can download them in the right file name. // see http://support.microsoft.com/kb/260519 and http://www.boutell.com/newfaq/creating/forcedownload.html rsp.setHeader("Content-Disposition", "attachment; filename=" + fileName); InputStream in = con.getInputStream(); rsp.serveFile(req, in, con.getLastModified(), con.getContentLength(), "*.jar" ); in.close(); }
private FileInformation readFileInformation(URL url) { FileInformation fileInformation = new FileInformation(); URLConnection urlConnection; try { if (url.getProtocol().startsWith("http")) { urlConnection = url.openConnection(); ((HttpURLConnection) urlConnection).setRequestMethod("HEAD"); try (InputStream inputStream = urlConnection.getInputStream()) { fileInformation.length = urlConnection.getContentLength(); fileInformation.lastModified = urlConnection.getLastModified(); } } else { if (url.getProtocol().startsWith("file")) { File file = new File(url.getFile()); if (file.exists()) { fileInformation = new FileInformation(file); } } } } catch (IOException e) { if (LOG.isLoggable(Level.WARNING)) LOG.log(Level.WARNING, "Failed to obtain age and length of URL " + url, e); } return fileInformation; }
@Override public long lastModified() throws IOException { URL url = getURL(); if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) { // Proceed with file system resolution... return super.lastModified(); } else { // Try a URL connection last-modified header... URLConnection con = url.openConnection(); customizeConnection(con); return con.getLastModified(); } }
public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { URLConnection con = connect(); // since we end up redirecting users to jnlpJars/foo.jar/, set the content disposition // so that browsers can download them in the right file name. // see http://support.microsoft.com/kb/260519 and http://www.boutell.com/newfaq/creating/forcedownload.html rsp.setHeader("Content-Disposition", "attachment; filename=" + fileName); InputStream in = con.getInputStream(); rsp.serveFile(req, in, con.getLastModified(), con.getContentLength(), "*.jar"); in.close(); }
/** * returns true if the source in URL is newer than the class * NOTE: copied from GroovyClassLoader */ private static boolean isSourceNewer(URL source, ClassNode cls) { try { long lastMod; // Special handling for file:// protocol, as getLastModified() often reports // incorrect results (-1) if (source.getProtocol().equals("file")) { // Coerce the file URL to a File String path = source.getPath().replace('/', File.separatorChar).replace('|', ':'); File file = new File(path); lastMod = file.lastModified(); } else { URLConnection conn = source.openConnection(); lastMod = conn.getLastModified(); conn.getInputStream().close(); } return lastMod > getTimeStamp(cls); } catch (IOException e) { // if the stream can't be opened, let's keep the old reference return false; } } }
@Override public long lastModified() throws IOException { URL url = getURL(); if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) { // Proceed with file system resolution... return getFile().lastModified(); } // Try a URL connection last-modified header... URLConnection con = url.openConnection(); useCachesIfNecessary(con); if (con instanceof HttpURLConnection) { ((HttpURLConnection) con).setRequestMethod("HEAD"); } return con.getLastModified(); }