cachedresource.java

来自「很棒的web服务器源代码」· Java 代码 · 共 669 行 · 第 1/2 页

JAVA
669
字号
    /**     * returns the current freshness lifetime of this resource     * @return a long, the freshness lifetime, in seconds     */    public abstract int getFreshnessLifetime();    /**     * This methods return the CachedResource matching this request     * it allows lookup in the cache for alternatives     * @return a CachedResource depending on the request     */    public CachedResource lookupResource(Request request) {	return this;    }    /**     * Get this cached entry identifier     * @return a String, usually the URL of the resource     */    public String getIdentifier() {	return (String) getValue(ATTR_IDENTIFIER, null);    }    /**     * Get this cached entry content length.     * @return An integer, giving the content length, or <strong>-1</strong>     * if undefined.     */    public int getContentLength() {	return getInt(ATTR_CONTENT_LENGTH, -1);    }    /**     * Set the content length of that cached entry.     * @param length The new content length of that entry.     */    public void setContentLength(int length) {	setInt(ATTR_CONTENT_LENGTH, length);    }    /**     * Get this cached entry current content length.     * @return An integer, giving the current content length, or      * <strong>-1</strong> if undefined     */    public int getCurrentLength() {	return getInt(ATTR_CURRENT_LENGTH, -1);    }    /**     * Set the current length of that cached entry.     * @param length The current length of that entry.     */    public void setCurrentLength(int length) {	setInt(ATTR_CURRENT_LENGTH, length);    }    /**     * Get the load state value     * @return an integer, as defined in CachedResource     * @see org.w3c.www.protocol.http.cache.CachedResource     * The default is STATE_NOT_LOADED     */    public int getLoadState() {	return getInt(ATTR_LOAD_STATE, STATE_NOT_LOADED);    }    /**     * Set the loading state of this resource     * @param an integer, one of the state defined in CachedResource     * @see org.w3c.www.protocol.http.cache.CachedResource     */    public void setLoadState(int state) {	setInt(ATTR_LOAD_STATE, state);    }    /**     * Get the HTTP status of that cached entry.     * @return An integer HTTP status code, or <strong>-1</strong> if      * undefined.     */    public int getStatus() {	return getInt(ATTR_STATUS, -1);    }    /**     * Set the reply status for that entry.     * @param status The HTTP status code of that entry, or <strong>-1</strong>     * to undefine the previous setting.     */    public void setStatus(int status) {	setInt(ATTR_STATUS, status);    }    /**     * Get this Cached Resource last modification time.     * @return A long giving the date of the last modification time, or     *    <strong>-1</strong> if undefined.     */    public long getLastModified() {	return getLong(ATTR_REPLY_LAST_MODIFIED, (long) -1) ;    }    /**     * Set the last modified time of that cached entry.     * @param lastmodified The last modification date as a number of      * milliseconds since Java epoch, or <strong>-1</strong> to undefine     * previous setting.     */    public void setLastModified(long lastmodified) {	setLong(ATTR_REPLY_LAST_MODIFIED, lastmodified);    }    /**     * Get the Content-Type of the cached resource of <code>null</code> if     * there is no mime type (it should NEVER happen!)     * @return a MimeType     */    public abstract MimeType getContentType();    /**     * Set the Content-Type of this cached resource     * @param a MimeType, the mime type of this resource     */    public abstract void setContentType(MimeType type);    /**     * Get state of the resource, did someone ask for revalidation for     * the next request?     * @return a boolean, <code>true</code> if it will.     * -1</strong> if undefined.     */    public boolean getWillRevalidate() {	return invalidated;    }    /**     * Set this cached entry revalidate-on-next-request flag     * @param validate, a boolean, <code>true</code> if it will be revalidated     * next time.     */    public void setWillRevalidate(boolean invalidated) {	this.invalidated = invalidated;    }    /**     * Get this date, as a long     * @return a long, the date     * if undefined.     */    public long getDate() {	return getLong(ATTR_DATE, -1);    }    /**     * Set the content length of that cached entry.     * @param length The new content length of that entry.     */    public void setDate(long date) {	setLong(ATTR_DATE, date);    }    /**     * Set the cached file     * @param file     */    public void setFile(File file) {	setValue(ATTR_FILE, file);    }    /**     * Get the cached File.     * @return a File instance     */    public File getFile() {	return (File)getValue(ATTR_FILE, null);    }    /**     * Get the entity tag associated with that cached entry.     * @return The String encoded entity tag, or <strong>null</strong> if      * undefined.     */    public String getETag() {	return getString(ATTR_ETAG, null);    }    /**     * Associate an entity tag with that cached enrty.     * @param etag The entity tag of the entry, or <strong>null</strong>     * to reset the value.     */    public void setETag(String etag) {	setValue(ATTR_ETAG, etag);    }    /**     * Get the Content-MD5 associated with that cached entry.     * @return The String encoded Content-MD5, or <strong>null</strong> if      * undefined.     */    public String getContentMD5() {	return getString(ATTR_CONTENT_MD5, null);    }    /**     * Associate a Content-MD5 with that cached enrty.     * @param sum, the md5 sum as a string, see RFC2616,      * or <strong>null</strong>     * to reset the value.     */    public void setContentMD5(String sum) {	setValue(ATTR_CONTENT_MD5, sum);    }    /**     * Get the Content-Encoding associated with that cached entry.     * @return The String Content-Encoding, or <strong>null</strong> if      * undefined.     */    public String[] getContentEncoding() {	return (String[]) getValue(ATTR_CONTENT_ENCODING, null);    }    /**     * Associate a Content-Encoding with that cached enrty.     * @param sum, the encoding as a string,     * or <strong>null</strong>     * to reset the value.     */    public void setContentEncoding(String[] sum) {	setValue(ATTR_CONTENT_ENCODING, sum);    }    /**     * Get the Content-Language associated with that cached entry.     * @return The String Content-Language, or <strong>null</strong> if      * undefined.     */    public String[] getContentLanguage() {	return (String[]) getValue(ATTR_CONTENT_LANGUAGE, null);    }    /**     * Associate a Content-Language with that cached enrty.     * @param sum, the encoding as a string,     * or <strong>null</strong>     * to reset the value.     */    public void setContentLanguage(String[] language) {	setValue(ATTR_CONTENT_LANGUAGE, language);    }    /**     * Get the Vary associated with that cached entry.     * @return The String array of Vary, or <strong>null</strong> if      * undefined.     */    public String[] getVary() {	return (String[]) getValue(ATTR_VARY, null);    }    /**     * Associate a Vary with that cached enrty.     * @param sum, the header involved in the variant check as a string array,     * or <strong>null</strong>     * to reset the value.     */    public void setVary(String[] vary) {	setValue(ATTR_VARY, vary);    }    /**     * Get the extra headers stored for that resource.     * @return An ArrayDictionary with the extra headers, or <strong>null     * </strong> if undefined.     */    public ArrayDictionary getExtraHeaders() {	return (ArrayDictionary) getValue(ATTR_EXTRA_HEADERS, null);    }    /**     * Set a new set of extra headers for that resource.     * @param headers The new set of headers.     */    public void setExtraHeaders(ArrayDictionary a) {	setValue(ATTR_EXTRA_HEADERS, a);    }    /**     * Get the extra headers stored for that resource.     * @return An ArrayDictionary with the extra headers, or <strong>null     * </strong> if undefined.     */    public ArrayDictionary getConnegHeaders() {	return (ArrayDictionary) getValue(ATTR_CONNEG_HEADERS, null);    }    /**     * Set a new set of extra headers for that resource.     * @param headers The new set of headers.     */    public void setConnegHeaders(ArrayDictionary a) {	setValue(ATTR_CONNEG_HEADERS, a);    }    /**     * Delete this resource (and its associated file).     * @return the number of bytes saved.     */    public long delete() {	File file = getFile();	if (file != null)	    file.delete();	return getCurrentLength();    }    /**     * This cached entry has been checked valid, perform given request.     * @param request The request to perform.     * @return An Reply instance.     * @exception HttpException If something went wrong.     */    public abstract Reply perform(Request request)	throws HttpException;    /**     * This cached entry needs revalidation, it will modify the      * request to do that.     */    public abstract Request setRequestRevalidation(Request request);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?