ClickHouse/src/IO/WriteBufferFromOStream.cpp

52 lines
1.1 KiB
C++
Raw Normal View History

2018-07-09 20:36:58 +00:00
#include <IO/WriteBufferFromOStream.h>
#include <Common/MemoryTracker.h>
2018-07-09 20:36:58 +00:00
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())
2018-07-10 20:45:27 +00:00
throw Exception("Cannot write to ostream at offset " + std::to_string(count()),
ErrorCodes::CANNOT_WRITE_TO_OSTREAM);
2018-07-09 20:36:58 +00:00
}
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()
{
2021-11-10 22:58:56 +00:00
if (finalized)
return;
MemoryTracker::LockExceptionInThread lock(VariableContext::Global);
2021-11-10 22:58:56 +00:00
finalizeImpl();
2018-07-09 20:36:58 +00:00
}
}