2018-07-09 20:36:58 +00:00
|
|
|
#include <IO/WriteBufferFromOStream.h>
|
2023-06-22 11:56:20 +00:00
|
|
|
#include <Common/logger_useful.h>
|
2018-07-09 20:36:58 +00:00
|
|
|
|
2024-04-03 18:36:29 +00:00
|
|
|
#include <ostream>
|
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())
|
2023-06-26 10:02:09 +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_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|