2021-04-20 18:29:03 +00:00
|
|
|
#include "WriteBufferFromFileDecorator.h"
|
|
|
|
|
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
WriteBufferFromFileDecorator::WriteBufferFromFileDecorator(std::unique_ptr<WriteBuffer> impl_)
|
2021-04-20 18:29:03 +00:00
|
|
|
: WriteBufferFromFileBase(0, nullptr, 0), impl(std::move(impl_))
|
|
|
|
{
|
|
|
|
swap(*impl);
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
void WriteBufferFromFileDecorator::finalize()
|
2021-04-20 18:29:03 +00:00
|
|
|
{
|
|
|
|
if (finalized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
next();
|
|
|
|
impl->finalize();
|
|
|
|
|
|
|
|
finalized = true;
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
WriteBufferFromFileDecorator::~WriteBufferFromFileDecorator()
|
2021-04-20 18:29:03 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2021-04-27 10:19:22 +00:00
|
|
|
WriteBufferFromFileDecorator::finalize();
|
2021-04-20 18:29:03 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
tryLogCurrentException(__PRETTY_FUNCTION__);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
void WriteBufferFromFileDecorator::sync()
|
2021-04-20 18:29:03 +00:00
|
|
|
{
|
|
|
|
impl->sync();
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
std::string WriteBufferFromFileDecorator::getFileName() const
|
2021-04-20 18:29:03 +00:00
|
|
|
{
|
2021-04-20 18:52:58 +00:00
|
|
|
if (WriteBufferFromFileBase * buffer = dynamic_cast<WriteBufferFromFileBase*>(impl.get()))
|
|
|
|
return buffer->getFileName();
|
2021-04-20 18:29:03 +00:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2021-04-20 18:52:58 +00:00
|
|
|
void WriteBufferFromFileDecorator::nextImpl()
|
2021-04-20 18:29:03 +00:00
|
|
|
{
|
|
|
|
swap(*impl);
|
|
|
|
impl->next();
|
|
|
|
swap(*impl);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|