#pragma once #include #include #include #include #include namespace DB { class WriteBufferFromOStream : public BufferWithOwnMemory { private: std::ostream & ostr; void nextImpl() { if (!offset()) return; ostr.write(working_buffer.begin(), offset()); ostr.flush(); if (!ostr.good()) throw Exception("Cannot write to ostream", ErrorCodes::CANNOT_WRITE_TO_OSTREAM); } public: WriteBufferFromOStream(std::ostream & ostr_, size_t size = DBMS_DEFAULT_BUFFER_SIZE) : BufferWithOwnMemory(size), ostr(ostr_) {} ~WriteBufferFromOStream() { if (!std::uncaught_exception()) next(); } }; }