Wt: Wt::WStreamResource Class Reference

Wt 3.3.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Wt::WStreamResource Class Reference

An object which streams the data from a std::istream. More...

`#include <Wt/WStreamResource>`

Inheritance diagram for Wt::WStreamResource:
[legend]

List of all members.

## Public Member Functions
| WStreamResource (WObject *parent=0)
| Default constructor.
| WStreamResource (const std::string &mimeType, WObject *parent=0)
| Creates a new resource with given mime-type.
| ~WStreamResource ()
| Destructor.
void | setMimeType (const std::string &mimeType)
| Sets the mime-type.
const std::string & | mimeType () const
| Returns the mime-type.
void | setBufferSize (int size)
| Configures the buffer size.
int | bufferSize () const
| Returns the buffer size.
## Protected Member Functions
void | handleRequestPiecewise (const Http::Request &request, Http::Response &response, std::istream &input)
| Handles a request and streams the data from a std::istream.

## Detailed Description

An object which streams the data from a std::istream.

This class can be useful base for implementing resources which streams the data from std::istream derivatives.

The utility method handleRequestPiecewise() makes use of continuations to transmit data piecewise, without blocking a thread or requiring the whole data to be read in memory. The size of the buffer can be changed by using setBufferSize().

Example for a custom stream resource implementation:

    class MyStreamResource : public Wt::WStreamResource
    {
    public:
      MyStreamResource(const std::string& fileName, Wt::WObject *parent = 0)
        : Wt::WStreamResource(parent),
          fileName_(fileName)
      {
        suggestFileName("data.txt");
      }

      ~MyStreamResource() {
        beingDeleted();
      }

      void handleRequest(const Wt::Http::Request& request,
                         Wt::Http::Response& response) {
        std::ifstream r(fileName_.c_str(), std::ios::in | std::ios::binary);
        handleRequestPiecewise(request, response, r);
      }

    private:
      std::string fileName_;
    };

See also:
  WFileResource

## Constructor & Destructor Documentation

Wt::WStreamResource::WStreamResource | ( | WObject * | parent = `0` | ) |

Default constructor.

The mime type defaults to "text/plain".

Wt::WStreamResource::~WStreamResource | ( |  | ) |

Destructor.

It is up to the user to make sure that the resource is no longer in use (by e.g. a WImage).

## Member Function Documentation

int Wt::WStreamResource::bufferSize | ( |  | ) | const

Returns the buffer size.

See also:
  setBufferSize()

void Wt::WStreamResource::handleRequestPiecewise | ( | const Http::Request & | request,
|  | Http::Response & | response,
|  | std::istream & | input
| ) |  | `[protected]`

Handles a request and streams the data from a std::istream.

You can call this method from a custom handleRequest() implementations.

void Wt::WStreamResource::setBufferSize | ( | int | size | ) |

Configures the buffer size.

This configures the size of the buffer used to transmit the data piece by piece.

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator