ClickHouse/dbms/include/DB/IO/ReadBufferFromIStream.h

46 lines
782 B
C
Raw Normal View History

2010-05-28 19:13:55 +00:00
#ifndef DBMS_COMMON_READBUFFER_FROM_ISTREAM_H
#define DBMS_COMMON_READBUFFER_FROM_ISTREAM_H
#include <iostream>
#include <DB/Core/Exception.h>
#include <DB/Core/ErrorCodes.h>
2010-06-04 18:25:25 +00:00
#include <DB/IO/ReadBuffer.h>
#include <DB/IO/BufferWithOwnMemory.h>
2010-05-28 19:13:55 +00:00
namespace DB
{
class ReadBufferFromIStream : public BufferWithOwnMemory<ReadBuffer>
2010-05-28 19:13:55 +00:00
{
private:
std::istream & istr;
bool nextImpl()
2010-05-28 19:13:55 +00:00
{
istr.read(working_buffer.begin(), working_buffer.size());
2011-06-26 21:30:59 +00:00
size_t gcount = istr.gcount();
2010-05-28 19:13:55 +00:00
2011-06-26 21:30:59 +00:00
if (!gcount)
2010-05-28 19:13:55 +00:00
{
if (istr.eof())
return false;
2011-06-26 21:30:59 +00:00
else
2010-05-28 19:13:55 +00:00
throw Exception("Cannot read from istream", ErrorCodes::CANNOT_READ_FROM_ISTREAM);
}
2011-06-26 21:30:59 +00:00
else
working_buffer.resize(gcount);
2011-06-26 21:30:59 +00:00
2010-05-28 19:13:55 +00:00
return true;
}
2011-06-26 21:30:59 +00:00
public:
ReadBufferFromIStream(std::istream & istr_) : istr(istr_) {}
2010-05-28 19:13:55 +00:00
};
}
#endif