47 #include "BESStreamResponseHandler.h"
48 #include "BESRequestHandlerList.h"
49 #include "BESForbiddenError.h"
50 #include "BESNotFoundError.h"
51 #include "BESInternalError.h"
52 #include "BESDataNames.h"
53 #include "BESContainer.h"
54 #include "BESDataHandlerInterface.h"
56 #define BES_STREAM_BUFFER_SIZE 4096
58 BESStreamResponseHandler::BESStreamResponseHandler(
const string &name) :
63 BESStreamResponseHandler::~BESStreamResponseHandler()
67 extern volatile int bes_timeout;
81 d_response_object = 0;
90 if (bes_timeout != 0) {
105 if (dhi.containers.size() != 1) {
106 string err = (string)
"Unable to stream file: " +
"no container specified";
112 string filename = container->
access();
113 if (filename.empty()) {
114 string err = (string)
"Unable to stream file: " +
"filename not specified";
120 os.open(filename.c_str(), ios::in);
123 string serr = (string)
"Unable to stream file because it cannot be opened. file: '" + filename +
"' msg: ";
124 char *err = strerror(myerrno);
128 serr +=
"Unknown error";
133 if (myerrno == ENOENT || myerrno == ENOTDIR) {
142 char block[BES_STREAM_BUFFER_SIZE];
143 os.read(block,
sizeof block);
144 nbytes = os.gcount();
147 dhi.get_output_stream().write((
char*) block, nbytes);
149 os.read(block,
sizeof block);
150 nbytes = os.gcount();
177 strm << BESIndent::LMarg <<
"BESStreamResponseHandler::dump - (" << (
void *)
this <<
")" << endl;
180 BESIndent::UnIndent();
184 BESStreamResponseHandler::BESStreamResponseBuilder(
const string &name)
A container is something that holds data. E.G., a netcdf file or a database entry.
virtual std::string access()=0
returns the true name of this container
Structure storing information used by the BES to handle the request.
void first_container()
set the container pointer to the first container in the containers list
BESContainer * container
pointer to current container in this interface
error thrown if the BES is not allowed to access the resource requested
exception thrown if internal error encountered
error thrown if the resource requested cannot be found
handler object that knows how to create a specific response object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual void transmit(BESTransmitter *transmitter, BESDataHandlerInterface &r)
transmit the file, streaming it back to the client
virtual void execute(BESDataHandlerInterface &r)
executes the command 'get file <filename>;' by streaming the specified file