本文整理汇总了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());
}
}
示例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());
}
}
示例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);
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
}
}
示例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();
}
}
}
示例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;
}
}
示例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;
}
示例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;
}