eu.webtoolkit.jwt
Class WMemoryResource

java.lang.Object
  extended by eu.webtoolkit.jwt.WObject
      extended by eu.webtoolkit.jwt.WResource
          extended by eu.webtoolkit.jwt.WMemoryResource

public class WMemoryResource
extends WResource

A resource which streams data from memory.

This is suitable for relatively small resources, which still require some computation.

If creating the data requires computation which you would like to post-pone until the resource is served, then you may want to directly reimplement WResource instead and compute the data on the fly while streaming.


Nested Class Summary
 
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WResource
WResource.DispositionType
 
Constructor Summary
WMemoryResource()
          Create a new resource.
WMemoryResource(java.lang.String mimeType)
          Create a new resource.
 
Method Summary
 byte[] getData()
          Returns the data.
 java.lang.String getMimeType()
          Returns the mime type.
protected  void handleRequest(WebRequest request, WebResponse response)
          Handles a request.
 void setData(byte[] data)
          Set data.
 void setMimeType(java.lang.String mimeType)
          Changes the mime type.
 
Methods inherited from class eu.webtoolkit.jwt.WResource
dataChanged, dataReceived, generateUrl, getDispositionType, getInternalPath, getSuggestedFileName, getUrl, setChanged, setDispositionType, setInternalPath, setUploadProgress, suggestFileName, suggestFileName, write, write
 
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setObjectName, tr
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WMemoryResource

public WMemoryResource()
Create a new resource.

You must call setMimeType(String) and setData(byte[]) before using the resource.


WMemoryResource

public WMemoryResource(java.lang.String mimeType)
Create a new resource.

You must call setData(byte[]) before using the resource.

Method Detail

setData

public void setData(byte[] data)
Set data. The data is specified as bytes. If you want to set character data, you will need to encode the characters into bytes using the appropriate encoding.

Parameters:
data -

getMimeType

public java.lang.String getMimeType()
Returns the mime type.

Returns:
the mime type.

setMimeType

public void setMimeType(java.lang.String mimeType)
Changes the mime type.

This causes the resource to be refreshed in the browser by triggering WResource.dataChanged().

Parameters:
mimeType -

getData

public byte[] getData()
Returns the data.

Returns:
the data.

handleRequest

protected void handleRequest(WebRequest request,
                             WebResponse response)
                      throws java.io.IOException
Description copied from class: WResource
Handles a request.

Reimplement this method so that a proper response is generated for the given request. From the request object you can access request parameters and whether the request is a continuation request. In the response object, you should set the mime type and stream the output data.

Specified by:
handleRequest in class WResource
Parameters:
request - The request information
response - The response object
Throws:
java.io.IOException