2011-10-15 23:40:56 +00:00
|
|
|
#pragma once
|
2010-05-28 19:13:55 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
2010-05-28 19:13:55 +00:00
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
2010-05-28 19:13:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int CANNOT_READ_FROM_ISTREAM;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-27 18:22:14 +00:00
|
|
|
class ReadBufferFromIStream : public BufferWithOwnMemory<ReadBuffer>
|
2010-05-28 19:13:55 +00:00
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
std::istream & istr;
|
|
|
|
|
|
|
|
bool nextImpl() override
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2011-06-26 21:30:59 +00:00
|
|
|
|
|
|
|
public:
|
2017-04-01 07:20:54 +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
|
|
|
};
|
|
|
|
|
|
|
|
}
|