org.apache.wicket.resource
Class ByteArrayResource

java.lang.Object
  extended by org.apache.wicket.Resource
      extended by org.apache.wicket.markup.html.WebResource
          extended by org.apache.wicket.resource.ByteArrayResource
All Implemented Interfaces:
java.io.Serializable, IClusterable, IRequestListener, IResourceListener

public class ByteArrayResource
extends WebResource

This class can be used to easy make a Resource from a predefined byte array. If your data comes from a database then a DynamicWebResource is a better choice. Only use this class if you have to have the byte array in memory. Like a pdf that is generated on the fly.

Author:
Johan Compagner
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
ByteArrayResource(java.lang.String contentType, byte[] array)
          Creates a Resource from the given byte array with its content type
ByteArrayResource(java.lang.String contentType, byte[] array, java.util.Locale locale)
          Creates a Resource from the given byte array with its content type and the locale for which it is valid.
ByteArrayResource(java.lang.String contentType, byte[] array, java.util.Locale locale, java.lang.String filename)
          Creates a Resource from the given byte array with its content type and the locale for which it is valid.
ByteArrayResource(java.lang.String contentType, byte[] array, java.lang.String filename)
          Creates a Resource from the given byte array with its content type
 
Method Summary
 IResourceStream getResourceStream()
           
protected  void setHeaders(WebResponse response)
          Subclasses can override this to set there headers when the resource is being served.
 
Methods inherited from class org.apache.wicket.markup.html.WebResource
configureResponse, getCacheDuration
 
Methods inherited from class org.apache.wicket.Resource
getParameters, invalidate, isCacheable, onResourceRequested, setCacheable, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteArrayResource

public ByteArrayResource(java.lang.String contentType,
                         byte[] array)
Creates a Resource from the given byte array with its content type

Parameters:
contentType - The Content type of the array.
array - The binary content

ByteArrayResource

public ByteArrayResource(java.lang.String contentType,
                         byte[] array,
                         java.lang.String filename)
Creates a Resource from the given byte array with its content type

Parameters:
contentType - The Content type of the array.
array - The binary content
filename - The filename that will be set as the Content-Disposition header.

ByteArrayResource

public ByteArrayResource(java.lang.String contentType,
                         byte[] array,
                         java.util.Locale locale)
Creates a Resource from the given byte array with its content type and the locale for which it is valid.

Parameters:
contentType - The Content type of the array.
array - The binary content.
locale - The locale of this resource

ByteArrayResource

public ByteArrayResource(java.lang.String contentType,
                         byte[] array,
                         java.util.Locale locale,
                         java.lang.String filename)
Creates a Resource from the given byte array with its content type and the locale for which it is valid.

Parameters:
contentType - The Content type of the array.
array - The binary content.
locale - The locale of this resource
filename - The filename that will be set as the Content-Disposition header.
Method Detail

setHeaders

protected void setHeaders(WebResponse response)
Description copied from class: WebResource
Subclasses can override this to set there headers when the resource is being served. By default 2 headers will be set if the Resource is cacheable
 response.setDateHeader("Expires", System.currentTimeMillis() + (3600 * 1000));
 response.setHeader("Cache-Control", "max-age=" + 3600);
 
So if a resource wants to control this or doesn't want to set this info it should override this method and don't call super.

Overrides:
setHeaders in class WebResource
Parameters:
response - The WebResponse where set(Date)Header can be called on.
See Also:
WebResource.setHeaders(org.apache.wicket.protocol.http.WebResponse)

getResourceStream

public IResourceStream getResourceStream()
Specified by:
getResourceStream in class Resource
Returns:
Gets the resource to render to the requester
See Also:
Resource.getResourceStream()


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.