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>
|
2011-06-27 18:22:14 +00:00
|
|
|
#include <DB/IO/BufferWithOwnMemory.h>
|
2010-05-28 19:13:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2011-06-27 18:22:14 +00:00
|
|
|
class ReadBufferFromIStream : public BufferWithOwnMemory<ReadBuffer>
|
2010-05-28 19:13:55 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
std::istream & istr;
|
|
|
|
|
2011-06-24 21:08:26 +00:00
|
|
|
bool nextImpl()
|
2010-05-28 19:13:55 +00:00
|
|
|
{
|
2011-06-27 18:22:14 +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
|
2011-06-27 18:22:14 +00:00
|
|
|
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
|