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


Java HttpURLConnection.setIfModifiedSince方法代码示例

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


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

示例1: download

import java.net.HttpURLConnection; //导入方法依赖的package包/类
/**
 * Check if there is a new version of the script engine
 * 
 * @throws IOException
 *             if any error occur
 */
private void download() throws IOException {
    boolean is32 = "32".equals( System.getProperty( "sun.arch.data.model" ) );
    String fileName;
    final String os = System.getProperty( "os.name", "" ).toLowerCase();
    if( os.contains( "windows" ) ) {
        fileName = is32 ? "win32" : "win64";
    } else if( os.contains( "mac" ) ) {
        fileName = is32 ? "mac" : "mac64";
    } else if( os.contains( "linux" ) ) {
        fileName = is32 ? "linux-i686" : "linux-x86_64";
    } else {
        throw new IllegalStateException( "Unknown OS: " + os );
    }
    File target = new File( System.getProperty( "java.io.tmpdir" ) + "/SpiderMonkey" );
    URL url = new URL( "https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central/jsshell-" + fileName
                    + ".zip" );
    System.out.println( "\tDownload: " + url );
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    if( target.exists() ) {
        System.out.println( "\tUP-TP-DATE" );
        conn.setIfModifiedSince( target.lastModified() );
    }
    InputStream input = conn.getInputStream();
    command = target.getAbsolutePath() + "/js";
    if( conn.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED ) {
        return;
    }
    ZipInputStream zip = new ZipInputStream( input );
    long lastModfied = conn.getLastModified();
    do {
        ZipEntry entry = zip.getNextEntry();
        if( entry == null ) {
            break;
        }
        if( entry.isDirectory() ) {
            continue;
        }
        File file = new File( target, entry.getName() );
        file.getParentFile().mkdirs();

        Files.copy( zip, file.toPath(), StandardCopyOption.REPLACE_EXISTING );
        file.setLastModified( entry.getTime() );
        if( "js".equals( file.getName() ) ) {
            file.setExecutable( true );
        }
    } while( true );
    target.setLastModified( lastModfied );
}
 
开发者ID:i-net-software,项目名称:JWebAssembly,代码行数:55,代码来源:SpiderMonkey.java

示例2: updateManifestCacheFile

import java.net.HttpURLConnection; //导入方法依赖的package包/类
private boolean updateManifestCacheFile(String name, String localCache, String url, ServletContext context)
	throws IOException
{
	File downloadtmp = File.createTempFile(name, ".part");
	File tmplocation = new File(_filesCacheDir);
	if(!tmplocation.exists())
	{	tmplocation.mkdir(); }
	File cacheFile = new File(tmplocation, localCache);
	long lastUpdatedCache = -1;
	if(cacheFile.exists())
	{
		lastUpdatedCache = cacheFile.lastModified();
		long twentyFourHoursAgo = System.currentTimeMillis() - (24L * 36000L);
		if(lastUpdatedCache > twentyFourHoursAgo)
		{
			context.log("Skipping updating " + name + " catalog");
			return false;
		}
	}
	URL cacheURL = new URL(url);
	HttpURLConnection cacheConnection = (HttpURLConnection) cacheURL.openConnection();
	if(lastUpdatedCache > 0L)
	{	cacheConnection.setIfModifiedSince(lastUpdatedCache); }
	cacheConnection.connect();
	switch(cacheConnection.getResponseCode())
	{
		case HttpURLConnection.HTTP_OK:
			InputStream is = cacheConnection.getInputStream();
			if("application/octet-stream".equals(cacheConnection.getContentType()))
			{
				ZipInputStream zis = new ZipInputStream(is);
				zis.getNextEntry();
				is = zis;
			}
			FileOutputStream os = new FileOutputStream(cacheFile, false);
			byte[] buff = new byte[1024];
			for(int br = is.read(buff); br > 0; br = is.read(buff))
			{	os.write(buff, 0, br); }
			os.close();
			is.close();
			context.log("manifest " + name + " updated");
			break;
		case HttpURLConnection.HTTP_NOT_MODIFIED:
			context.log("manifest " + name + " not modified");
			break;
		default:
			context.log("error updating " + name + ", got return code " + cacheConnection.getResponseCode() +" with message " + cacheConnection.getResponseMessage());
	}
	cacheConnection.disconnect();
	return true;
}
 
开发者ID:zueski,项目名称:playswith,代码行数:52,代码来源:ManifestServlet.java


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