#pragma once #include #include #include #include #include namespace DB { class ReadBufferFromIStream : public BufferWithOwnMemory { private: std::istream & istr; bool nextImpl() { istr.read(internal_buffer.begin(), internal_buffer.size()); size_t gcount = istr.gcount(); if (!gcount) { if (istr.eof()) return false; else throw Exception("Cannot read from istream", ErrorCodes::CANNOT_READ_FROM_ISTREAM); } else working_buffer.resize(gcount); return true; } public: ReadBufferFromIStream(std::istream & istr_, size_t size = DBMS_DEFAULT_BUFFER_SIZE) : BufferWithOwnMemory(size), istr(istr_) {} }; }