mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 16:42:05 +00:00
42 lines
662 B
C++
42 lines
662 B
C++
#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/IO/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);
|
|
ostr.flush();
|
|
pos = internal_buffer;
|
|
|
|
if (!ostr.good())
|
|
throw Exception("Cannot write to ostream", ErrorCodes::CANNOT_WRITE_TO_OSTREAM);
|
|
}
|
|
|
|
~WriteBufferFromOStream()
|
|
{
|
|
next();
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|