Class WMemoryResource
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
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
ConstructorDescriptionCreate a new resource.WMemoryResource
(String mimeType) Create a new resource. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getData()
Returns the data.Returns the mime type.protected void
handleRequest
(WebRequest request, WebResponse response) Handles a request.void
setData
(byte[] data) Set data.void
setMimeType
(String mimeType) Changes the mime type.Methods inherited from class eu.webtoolkit.jwt.WResource
dataChanged, dataExceeded, dataReceived, generateUrl, getDispositionType, getInternalPath, getSuggestedFileName, getUrl, getVersion, incrementVersion, isInvalidAfterChanged, setChanged, setDispositionType, setInternalPath, setInvalidAfterChanged, setTakesUpdateLock, setUploadProgress, suggestFileName, suggestFileName, takesUpdateLock, write, write
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
-
Constructor Details
-
WMemoryResource
public WMemoryResource()Create a new resource.You must call
setMimeType(String)
andsetData(byte[])
before using the resource. -
WMemoryResource
Create a new resource.You must call
setData(byte[])
before using the resource.
-
-
Method Details
-
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
Returns the mime type.- Returns:
- the mime type.
-
setMimeType
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
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 classWResource
- Parameters:
request
- The request informationresponse
- The response object- Throws:
IOException
-