com.opensymphony.oscache.web.filter
Class ResponseContent

java.lang.Object
  extended by com.opensymphony.oscache.web.filter.ResponseContent
All Implemented Interfaces:
Serializable

public class ResponseContent
extends Object
implements Serializable

Holds the servlet response in a byte array so that it can be held in the cache (and, since this class is serializable, optionally persisted to disk).

Version:
$Revision: 362 $
Author:
Serge Knystautas
See Also:
Serialized Form

Field Summary
private  ByteArrayOutputStream bout
           
private  byte[] content
           
private  String contentEncoding
           
private  String contentType
           
private  long expires
           
private  long lastModified
           
private  Locale locale
           
private  long maxAge
           
 
Constructor Summary
ResponseContent()
           
 
Method Summary
 void commit()
          Called once the response has been written in its entirety.
 String getContentEncoding()
           
 String getContentType()
           
 long getExpires()
           
 long getLastModified()
           
 long getMaxAge()
          Returns the max age of the content in miliseconds.
 OutputStream getOutputStream()
          Get an output stream.
 int getSize()
          Gets the size of this cached content.
 boolean isContentGZiped()
           
 void setContentEncoding(String contentEncoding)
           
 void setContentType(String value)
          Set the content type.
 void setExpires(long value)
          Sets the expires date and time in miliseconds.
 void setLastModified(long value)
           
 void setLocale(Locale value)
          Set the Locale.
 void setMaxAge(long value)
          Sets the max age date and time in miliseconds.
 void writeTo(javax.servlet.ServletResponse response)
          Writes this cached data out to the supplied ServletResponse.
 void writeTo(javax.servlet.ServletResponse response, boolean fragment, boolean acceptsGZip)
          Writes this cached data out to the supplied ServletResponse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bout

private transient ByteArrayOutputStream bout

locale

private Locale locale

contentEncoding

private String contentEncoding

contentType

private String contentType

content

private byte[] content

expires

private long expires

lastModified

private long lastModified

maxAge

private long maxAge
Constructor Detail

ResponseContent

public ResponseContent()
Method Detail

getContentType

public String getContentType()

setContentType

public void setContentType(String value)
Set the content type. We capture this so that when we serve this data from cache, we can set the correct content type on the response.


getLastModified

public long getLastModified()

setLastModified

public void setLastModified(long value)

getContentEncoding

public String getContentEncoding()

setContentEncoding

public void setContentEncoding(String contentEncoding)

setLocale

public void setLocale(Locale value)
Set the Locale. We capture this so that when we serve this data from cache, we can set the correct locale on the response.


getExpires

public long getExpires()
Returns:
the expires date and time in miliseconds when the content will be stale

setExpires

public void setExpires(long value)
Sets the expires date and time in miliseconds.

Parameters:
value - time in miliseconds when the content will expire

getMaxAge

public long getMaxAge()
Returns the max age of the content in miliseconds. If expires header and cache control are enabled both, both will be equal.

Returns:
the max age of the content in miliseconds, if -1 max-age is disabled

setMaxAge

public void setMaxAge(long value)
Sets the max age date and time in miliseconds. If the parameter is -1, the max-age parameter won't be set by default in the Cache-Control header.

Parameters:
value - sets the intial

getOutputStream

public OutputStream getOutputStream()
Get an output stream. This is used by the SplitServletOutputStream to capture the original (uncached) response into a byte array.

Returns:
the original (uncached) response, returns null if response is already committed.

getSize

public int getSize()
Gets the size of this cached content.

Returns:
The size of the content, in bytes. If no content exists, this method returns -1.

commit

public void commit()
Called once the response has been written in its entirety. This method commits the response output stream by converting the output stream into a byte array.


writeTo

public void writeTo(javax.servlet.ServletResponse response)
             throws IOException
Writes this cached data out to the supplied ServletResponse.

Parameters:
response - The servlet response to output the cached content to.
Throws:
IOException

writeTo

public void writeTo(javax.servlet.ServletResponse response,
                    boolean fragment,
                    boolean acceptsGZip)
             throws IOException
Writes this cached data out to the supplied ServletResponse.

Parameters:
response - The servlet response to output the cached content to.
fragment - is true if this content a fragment or part of a page
acceptsGZip - is true if client browser supports gzip compression
Throws:
IOException

isContentGZiped

public boolean isContentGZiped()
Returns:
true if the content is GZIP compressed


Copyright © 2011 OpenSymphony. All Rights Reserved.