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-01-23 21:13:58 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|