ClickHouse/dbms/include/DB/Core/WriteBufferFromOStream.h

41 lines
648 B
C
Raw Normal View History

2010-06-01 13:35:09 +00:00
#ifndef DBMS_COMMON_WRITEBUFFER_FROM_OSTREAM_H
#define DBMS_COMMON_WRITEBUFFER_FROM_OSTREAM_H
#include <iostream>
#include <DB/Core/Exception.h>
#include <DB/Core/ErrorCodes.h>
#include <DB/Core/WriteBuffer.h>
namespace DB
{
class WriteBufferFromOStream : public WriteBuffer
{
private:
std::ostream & ostr;
public:
WriteBufferFromOStream(std::ostream & ostr_) : ostr(ostr_) {}
void next()
{
ostr.write(internal_buffer, pos - internal_buffer);
pos = internal_buffer;
if (!ostr.good())
throw Exception("Cannot write to ostream", ErrorCodes::CANNOT_WRITE_TO_OSTREAM);
}
~WriteBufferFromOStream()
{
next();
}
};
}
#endif