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

49 lines
819 B
C
Raw Normal View History

2011-10-15 23:40:56 +00:00
#pragma once
2010-05-28 19:13:55 +00:00
#include <iostream>
2015-10-05 01:35:28 +00:00
#include <DB/Common/Exception.h>
2010-05-28 19:13:55 +00:00
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
{
namespace ErrorCodes
{
extern const int CANNOT_READ_FROM_ISTREAM;
}
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(internal_buffer.begin(), internal_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:
2011-11-29 17:23:30 +00:00
ReadBufferFromIStream(std::istream & istr_, size_t size = DBMS_DEFAULT_BUFFER_SIZE)
: BufferWithOwnMemory<ReadBuffer>(size), istr(istr_) {}
2010-05-28 19:13:55 +00:00
};
}