2011-10-15 23:40:56 +00:00
|
|
|
#pragma once
|
2010-05-28 19:13:55 +00:00
|
|
|
|
|
|
|
#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
|
|
|
{
|
2012-02-09 23:49:04 +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
|
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:
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|