ClickHouse/src/IO/WriteBufferFromOStream.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.3 KiB
C++
Raw Normal View History

2018-07-09 20:36:58 +00:00
#include <IO/WriteBufferFromOStream.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())
2023-06-22 11:01:28 +00:00
{
/// FIXME do not call finalize in dtors (and remove iostreams)
bool avoid_throwing_exceptions = std::uncaught_exceptions();
if (avoid_throwing_exceptions)
LOG_ERROR(&Poco::Logger::get("WriteBufferFromOStream"), "Cannot write to ostream at offset {}. Stack trace: {}", count(), StackTrace().toString());
else
throw Exception(ErrorCodes::CANNOT_WRITE_TO_OSTREAM, "Cannot write to ostream at offset {}", count());
}
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-11 17:27:23 +00:00
finalize();
2018-07-09 20:36:58 +00:00
}
}