| 1 | #include <IO/ReadBufferFromIStream.h> |
|---|---|
| 2 | #include <Common/Exception.h> |
| 3 | |
| 4 | |
| 5 | namespace DB |
| 6 | { |
| 7 | |
| 8 | namespace ErrorCodes |
| 9 | { |
| 10 | extern const int CANNOT_READ_FROM_ISTREAM; |
| 11 | } |
| 12 | |
| 13 | bool ReadBufferFromIStream::nextImpl() |
| 14 | { |
| 15 | istr.read(internal_buffer.begin(), internal_buffer.size()); |
| 16 | size_t gcount = istr.gcount(); |
| 17 | |
| 18 | if (!gcount) |
| 19 | { |
| 20 | if (istr.eof()) |
| 21 | return false; |
| 22 | |
| 23 | if (istr.fail()) |
| 24 | throw Exception("Cannot read from istream at offset "+ std::to_string(count()), ErrorCodes::CANNOT_READ_FROM_ISTREAM); |
| 25 | |
| 26 | throw Exception("Unexpected state of istream at offset "+ std::to_string(count()), ErrorCodes::CANNOT_READ_FROM_ISTREAM); |
| 27 | } |
| 28 | else |
| 29 | working_buffer.resize(gcount); |
| 30 | |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | ReadBufferFromIStream::ReadBufferFromIStream(std::istream & istr_, size_t size) |
| 35 | : BufferWithOwnMemory<ReadBuffer>(size), istr(istr_) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | } |
| 40 |