Tabnine Logo
URLConnection.getLastModified
Code IndexAdd Tabnine to your IDE (free)

How to use
getLastModified
method
in
java.net.URLConnection

Best Java code snippets using java.net.URLConnection.getLastModified (Showing top 20 results out of 3,438)

Refine searchRefine arrow

  • URL.openConnection
  • URLConnection.getInputStream
origin: org.netbeans.api/org-openide-filesystems

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);
  }
}
origin: jenkinsci/jenkins

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();
}
origin: plutext/docx4j

/**
 * 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;
  }
}
origin: jMonkeyEngine/jmonkeyengine

  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) { }
origin: jenkinsci/jenkins

URLConnection uc = url.openConnection();
return uc.getLastModified();
origin: jenkinsci/jenkins

long sourceTimestamp = con.getLastModified();
InputStream in = archive.getProtocol().startsWith("http") ? ProxyConfiguration.getInputStream(archive) : con.getInputStream();
CountingInputStream cis = new CountingInputStream(in);
try {
origin: jooby-project/jooby

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();
 }
}
origin: xalan/xalan

/**
 * 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());
}
}
origin: pentaho/mondrian

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 + "'");
  }
}
origin: org.freemarker/freemarker

  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")) {
origin: line/armeria

@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;
}
origin: org.jenkins-ci.main/jenkins-core

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();
}
origin: dropwizard/dropwizard

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) {
origin: spring-projects/spring-framework

@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;
}
origin: org.jvnet.hudson.main/hudson-core

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();
}
origin: chewiebug/GCViewer

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;
}
origin: perwendel/spark

@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();
  }
}
origin: org.eclipse.hudson/hudson-core

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();
}
origin: org.codehaus.groovy/groovy

  /**
   * 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;
    }
  }
}
origin: micronaut-projects/micronaut-core

@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();
}
java.netURLConnectiongetLastModified

Javadoc

Returns the value of the response header field last-modified or 0 if this value is not set.

Popular methods of URLConnection

  • getInputStream
    Returns an input stream that reads from this open connection. A SocketTimeoutException can be thrown
  • setUseCaches
    Sets the value of the useCaches field of thisURLConnection to the specified value. Some protocols do
  • connect
    Opens a communications link to the resource referenced by this URL, if such a connection has not alr
  • setRequestProperty
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • getOutputStream
    Returns an output stream that writes to this connection.
  • setConnectTimeout
    Sets a specified timeout value, in milliseconds, to be used when opening a communications link to th
  • setDoOutput
    Sets the value of the doOutput field for thisURLConnection to the specified value. A URL connection
  • getContentLength
    Returns the value of the content-length header field.Note: #getContentLengthLong()should be preferre
  • setReadTimeout
    Sets the read timeout to a specified timeout, in milliseconds. A non-zero value specifies the timeou
  • getContentType
    Returns the value of the content-type header field.
  • getHeaderField
    Returns the value of the named header field. If called on a connection that sets the same header mul
  • setDoInput
    Sets the value of the doInput field for thisURLConnection to the specified value. A URL connection c
  • getHeaderField,
  • setDoInput,
  • addRequestProperty,
  • getURL,
  • getContentEncoding,
  • guessContentTypeFromName,
  • setDefaultUseCaches,
  • getFileNameMap,
  • getContent

Popular in Java

  • Running tasks concurrently on multiple threads
  • onRequestPermissionsResult (Fragment)
  • startActivity (Activity)
  • getSystemService (Context)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • Path (java.nio.file)
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now