当前位置: 首页>>代码示例>>Java>>正文


Java URLConnection.getLastModified方法代码示例

本文整理汇总了Java中java.net.URLConnection.getLastModified方法的典型用法代码示例。如果您正苦于以下问题:Java URLConnection.getLastModified方法的具体用法?Java URLConnection.getLastModified怎么用?Java URLConnection.getLastModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URLConnection的用法示例。


在下文中一共展示了URLConnection.getLastModified方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
/**
 * 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 = Paths.get(url.toURI()).toFile();
                timestamp = localfile.lastModified();
            }
        }
        return(timestamp);
    }
    // Brutal handling of all exceptions
    catch (Exception e) {
        return(System.currentTimeMillis());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:DocumentCache.java

示例2: main

import java.net.URLConnection; //导入方法依赖的package包/类
public static void main(String[] args) {
    try {
        File f = File.createTempFile("test", null);
        f.deleteOnExit();
        String s = f.getAbsolutePath();
        s = s.startsWith("/") ? s : "/" + s;
        URL url = new URL("file://localhost"+s);
        URLConnection conn = null;
        conn = url.openConnection();
        conn.connect();
        if (f.lastModified() != conn.getLastModified())
            throw new RuntimeException("file.lastModified() & FileURLConnection.getLastModified() should be equal");
        f.delete();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:GetLastModified.java

示例3: initPumping

import java.net.URLConnection; //导入方法依赖的package包/类
private void initPumping(URLConnection connection) throws IOException {
    final Date lastModif = new Date(connection.getLastModified());
    final URL realUrl = connection.getURL();
    final String accept = connection.getHeaderField("Accept-Ranges");
    final boolean acceptBytes = accept != null ? accept.contains("bytes"): false;
    final long length = connection.getContentLength();
    pumping.init(realUrl, length, lastModif, acceptBytes);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:Pump.java

示例4: timeFromDateHeaderField

import java.net.URLConnection; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:XMLFileSystem.java

示例5: getRepresentationInternal

import java.net.URLConnection; //导入方法依赖的package包/类
private Object getRepresentationInternal(final long now) throws Exception {
    URL url;
    try {
        url = resource.getURL();
    } catch (final IOException e) {
        url = null;
    }
    long newLastModified;
    URLConnection conn;
    if (url != null) {
        if ("file".equals(url.getProtocol())) {
            newLastModified = resource.getFile().lastModified();
            conn = null;
        } else {
            conn = url.openConnection();
            newLastModified = conn.getLastModified();
        }
    } else {
        newLastModified = 0;
        conn = null;
    }
    lastChecked = now;
    if (representation == null || newLastModified != lastModified) {
        lastModified = newLastModified;
        try (final InputStream in = conn == null ? resource.getInputStream() : conn.getInputStream()) {
            representation = loadRepresentation(in);
        }
    } else if (conn != null) {
        conn.getInputStream().close();
    }
    return representation;
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:33,代码来源:ResourceRepresentation.java

示例6: isResourceChanged

import java.net.URLConnection; //导入方法依赖的package包/类
private boolean isResourceChanged(URLConnection urlConnection)
throws IOException {
    if(urlConnection instanceof HttpURLConnection) {
        return ((HttpURLConnection)urlConnection).getResponseCode() ==
            HttpURLConnection.HTTP_NOT_MODIFIED;
    }
    return lastModified == urlConnection.getLastModified();
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:9,代码来源:UrlModuleSourceProvider.java

示例7: getFileLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
@Override
public long getFileLastModified(String path, boolean virtual)
        throws IOException {
    long lastModified = 0;
    try {
        URLConnection urlConnection = getURLConnection(path, virtual);
        lastModified = urlConnection.getLastModified();
    } catch (IOException e) {
        // Ignore this. It will always fail for non-file based includes
    }
    return lastModified;
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:SSIServletExternalResolver.java

示例8: getFileLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
public long getFileLastModified(String path, boolean virtual)
        throws IOException {
    long lastModified = 0;
    try {
        URLConnection urlConnection = getURLConnection(path, virtual);
        lastModified = urlConnection.getLastModified();
    } catch (IOException e) {
        // Ignore this. It will always fail for non-file based includes
    }
    return lastModified;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:SSIServletExternalResolver.java

示例9: getFileLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
@Override
public long getFileLastModified(String path, boolean virtual) throws IOException {
	long lastModified = 0;
	try {
		URLConnection urlConnection = getURLConnection(path, virtual);
		lastModified = urlConnection.getLastModified();
	} catch (IOException e) {
		// Ignore this. It will always fail for non-file based includes
	}
	return lastModified;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:12,代码来源:SSIServletExternalResolver.java

示例10: isResourceChanged

import java.net.URLConnection; //导入方法依赖的package包/类
private boolean isResourceChanged(URLConnection urlConnection) 
throws IOException {
    if(urlConnection instanceof HttpURLConnection) {
        return ((HttpURLConnection)urlConnection).getResponseCode() == 
            HttpURLConnection.HTTP_NOT_MODIFIED;
    }
    return lastModified == urlConnection.getLastModified();
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:9,代码来源:UrlModuleSourceProvider.java

示例11: load

import java.net.URLConnection; //导入方法依赖的package包/类
protected void load() throws IOException {
    if (array == null) {
        final URLConnection c = url.openConnection();
        try (InputStream in = c.getInputStream()) {
            array = cs == null ? readFully(in) : readFully(in, cs);
            length = array.length;
            lastModified = c.getLastModified();
            debug("loaded content for ", url);
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Source.java

示例12: checkUnpackLib

import java.net.URLConnection; //导入方法依赖的package包/类
private static void checkUnpackLib(String filename) {
    String path = "/native/" + filename;
    URL resource = NativeLibraryLoader.class.getResource(path);
    if (resource == null) {
        System.err.println("Not available in classpath: " + path);
    } else {
        File file = new File(filename);
        try {
            URLConnection urlConnection = resource.openConnection();
            int length = urlConnection.getContentLength();
            long lastModified = urlConnection.getLastModified();
            if (!file.exists() || file.length() != length || file.lastModified() != lastModified) {
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                try {
                    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                    try {
                        IoUtils.copyAllBytes(in, out);
                    } finally {
                        IoUtils.safeClose(out);
                    }
                } finally {
                    IoUtils.safeClose(in);
                }
                if (lastModified > 0) {
                    file.setLastModified(lastModified);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:objectbox,项目名称:objectbox-java,代码行数:33,代码来源:NativeLibraryLoader.java

示例13: test

import java.net.URLConnection; //导入方法依赖的package包/类
static void test(String s) throws Exception {
    URL url = new URL(s);
    URLConnection conn = url.openConnection();
    if (conn.getLastModified() == 0) {
        System.out.println("Failed: getLastModified returned 0 for URL: " + s);
        testFailed = true;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:GetLastModified.java

示例14: getFileLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
public long getFileLastModified( String path, boolean virtual ) throws IOException {
long lastModified = 0;

URLConnection urlConnection = getURLConnection( path, virtual );
lastModified = urlConnection.getLastModified();
return lastModified;		
   }
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:8,代码来源:SSIServletExternalResolver.java

示例15: getLastModified

import java.net.URLConnection; //导入方法依赖的package包/类
public static long getLastModified(URLConnection connection) throws IOException
{
  long modified;
  if (connection instanceof JarURLConnection)
  {
    // The following hack is required to work-around a JDK bug.
    // getLastModified() on a JAR entry URL delegates to the actual JAR file
    // rather than the JAR entry.
    // This opens internally, and does not close, an input stream to the JAR
    // file.
    // In turn, you cannot close it by yourself, because it's internal.
    // The work-around is to get the modification date of the JAR file
    // manually,
    // and then close that connection again.

    URL jarFileUrl = ((JarURLConnection) connection).getJarFileURL();
    URLConnection jarFileConnection = jarFileUrl.openConnection();

    try
    {
      modified = jarFileConnection.getLastModified();
    }
    finally
    {
      try
      {
        jarFileConnection.getInputStream().close();
      }
      catch (Exception exception)
      {
        // Ignored
      }
    }
  }
  else
  {
    modified = connection.getLastModified();
  }

  return modified;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:42,代码来源:URLUtils.java


注:本文中的java.net.URLConnection.getLastModified方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。