ClickHouse/dbms/IO/ReadBufferFromIStream.cpp

40 lines
882 B
C++
Raw Normal View History

2018-07-09 20:36:58 +00:00
#include <IO/ReadBufferFromIStream.h>
#include <Common/Exception.h>
namespace DB
{
namespace ErrorCodes
{
extern const int CANNOT_READ_FROM_ISTREAM;
}
bool ReadBufferFromIStream::nextImpl()
{
istr.read(internal_buffer.begin(), internal_buffer.size());
size_t gcount = istr.gcount();
if (!gcount)
{
if (istr.eof())
return false;
2018-07-10 00:35:00 +00:00
if (istr.fail())
2018-07-11 12:50:23 +00:00
throw Exception("Cannot read from istream at offset " + std::to_string(count()), ErrorCodes::CANNOT_READ_FROM_ISTREAM);
2018-07-10 00:35:00 +00:00
2018-07-11 12:50:23 +00:00
throw Exception("Unexpected state of istream at offset " + std::to_string(count()), ErrorCodes::CANNOT_READ_FROM_ISTREAM);
2018-07-09 20:36:58 +00:00
}
else
working_buffer.resize(gcount);
return true;
}
ReadBufferFromIStream::ReadBufferFromIStream(std::istream & istr_, size_t size)
: BufferWithOwnMemory<ReadBuffer>(size), istr(istr_)
{
}
}