mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
56 lines
1.0 KiB
C++
56 lines
1.0 KiB
C++
#include <IO/WriteBufferFromOStream.h>
|
|
#include <Common/Exception.h>
|
|
|
|
|
|
namespace DB
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
{
|
|
extern const int CANNOT_WRITE_TO_OSTREAM;
|
|
}
|
|
|
|
void WriteBufferFromOStream::nextImpl()
|
|
{
|
|
if (!offset())
|
|
return;
|
|
|
|
ostr->write(working_buffer.begin(), offset());
|
|
ostr->flush();
|
|
|
|
if (!ostr->good())
|
|
throw Exception("Cannot write to ostream at offset " + std::to_string(count()),
|
|
ErrorCodes::CANNOT_WRITE_TO_OSTREAM);
|
|
}
|
|
|
|
WriteBufferFromOStream::WriteBufferFromOStream(
|
|
size_t size,
|
|
char * existing_memory,
|
|
size_t alignment)
|
|
: BufferWithOwnMemory<WriteBuffer>(size, existing_memory, alignment)
|
|
{
|
|
}
|
|
|
|
WriteBufferFromOStream::WriteBufferFromOStream(
|
|
std::ostream & ostr_,
|
|
size_t size,
|
|
char * existing_memory,
|
|
size_t alignment)
|
|
: BufferWithOwnMemory<WriteBuffer>(size, existing_memory, alignment), ostr(&ostr_)
|
|
{
|
|
}
|
|
|
|
WriteBufferFromOStream::~WriteBufferFromOStream()
|
|
{
|
|
try
|
|
{
|
|
next();
|
|
}
|
|
catch (...)
|
|
{
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
}
|
|
}
|
|
|
|
}
|