Class 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.

  • Constructor Details

    • WMemoryResource

      public WMemoryResource()
      Create a new resource.

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

    • WMemoryResource

      public WMemoryResource(String mimeType)
      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.
      data -
    • getMimeType

      public String getMimeType()
      Returns the mime type.
      the mime type.
    • setMimeType

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

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

      mimeType -
    • getData

      public byte[] getData()
      Returns the data.
      the data.
    • handleRequest

      protected void handleRequest(WebRequest request, WebResponse response) throws 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
      request - The request information
      response - The response object