當前位置: 首頁>>代碼示例>>Java>>正文


Java URLConnection.getHeaderFieldDate方法代碼示例

本文整理匯總了Java中java.net.URLConnection.getHeaderFieldDate方法的典型用法代碼示例。如果您正苦於以下問題:Java URLConnection.getHeaderFieldDate方法的具體用法?Java URLConnection.getHeaderFieldDate怎麽用?Java URLConnection.getHeaderFieldDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.URLConnection的用法示例。


在下文中一共展示了URLConnection.getHeaderFieldDate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: calculateExpiry

import java.net.URLConnection; //導入方法依賴的package包/類
private long calculateExpiry(URLConnection urlConnection,
        long request_time, UrlConnectionExpiryCalculator
        urlConnectionExpiryCalculator)
{
    if("no-cache".equals(urlConnection.getHeaderField("Pragma"))) {
        return 0L;
    }
    final String cacheControl = urlConnection.getHeaderField(
            "Cache-Control");
    if(cacheControl != null ) {
        if(cacheControl.indexOf("no-cache") != -1) {
            return 0L;
        }
        final int max_age = getMaxAge(cacheControl);
        if(-1 != max_age) {
            final long response_time = System.currentTimeMillis();
            final long apparent_age = Math.max(0, response_time -
                    urlConnection.getDate());
            final long corrected_received_age = Math.max(apparent_age,
                    urlConnection.getHeaderFieldInt("Age", 0) * 1000L);
            final long response_delay = response_time - request_time;
            final long corrected_initial_age = corrected_received_age +
                response_delay;
            final long creation_time = response_time -
                corrected_initial_age;
            return max_age * 1000L + creation_time;
        }
    }
    final long explicitExpiry = urlConnection.getHeaderFieldDate(
            "Expires", -1L);
    if(explicitExpiry != -1L) {
        return explicitExpiry;
    }
    return urlConnectionExpiryCalculator == null ? 0L :
        urlConnectionExpiryCalculator.calculateExpiry(urlConnection);
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:37,代碼來源:UrlModuleSourceProvider.java

示例2: calculateExpiry

import java.net.URLConnection; //導入方法依賴的package包/類
private long calculateExpiry(URLConnection urlConnection, 
        long request_time, UrlConnectionExpiryCalculator 
        urlConnectionExpiryCalculator)
{
    if("no-cache".equals(urlConnection.getHeaderField("Pragma"))) {
        return 0L;
    }
    final String cacheControl = urlConnection.getHeaderField(
            "Cache-Control");
    if(cacheControl != null ) {
        if(cacheControl.indexOf("no-cache") != -1) {
            return 0L;
        }
        final int max_age = getMaxAge(cacheControl);
        if(-1 != max_age) {
            final long response_time = System.currentTimeMillis();
            final long apparent_age = Math.max(0, response_time - 
                    urlConnection.getDate());
            final long corrected_received_age = Math.max(apparent_age, 
                    urlConnection.getHeaderFieldInt("Age", 0) * 1000L);
            final long response_delay = response_time - request_time;
            final long corrected_initial_age = corrected_received_age + 
                response_delay;
            final long creation_time = response_time - 
                corrected_initial_age;
            return max_age * 1000L + creation_time;
        }
    }
    final long explicitExpiry = urlConnection.getHeaderFieldDate(
            "Expires", -1L);
    if(explicitExpiry != -1L) {
        return explicitExpiry;
    }
    return urlConnectionExpiryCalculator == null ? 0L : 
        urlConnectionExpiryCalculator.calculateExpiry(urlConnection);
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:37,代碼來源:UrlModuleSourceProvider.java


注:本文中的java.net.URLConnection.getHeaderFieldDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。