ClickHouse/dbms/include/DB/IO/RemoteReadBuffer.h
2014-04-08 11:24:21 +04:00

71 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <DB/IO/ReadBufferFromHTTP.h>
#include "ReadHelpers.h"
namespace DB
{
/** Позволяет читать файл с удалённого сервера через riod.
*/
class RemoteReadBuffer : public ReadBuffer
{
private:
Poco::SharedPtr<ReadBufferFromHTTP> impl;
public:
RemoteReadBuffer(
const std::string & host,
int port,
const std::string & path,
bool compress = true,
size_t timeout = 0,
size_t buffer_size = DBMS_DEFAULT_BUFFER_SIZE)
: ReadBuffer(nullptr, 0)
{
ReadBufferFromHTTP::Params params = {
std::make_pair("action", "read"),
std::make_pair("path", path),
std::make_pair("compress", (compress ? "true" : "false"))};
impl = new ReadBufferFromHTTP(host, port, params, timeout, buffer_size);
}
bool nextImpl()
{
if (!impl->next())
return false;
internal_buffer = impl->buffer();
working_buffer = internal_buffer;
return true;
}
/// Вернуть список имен файлов в директории.
static std::vector<std::string> listFiles(
const std::string & host,
int port,
const std::string & path,
size_t timeout = 0)
{
ReadBufferFromHTTP::Params params = {
std::make_pair("action", "list"),
std::make_pair("path", path)};
ReadBufferFromHTTP in(host, port, params, timeout);
std::vector<std::string> files;
while (!in.eof())
{
std::string s;
readString(s, in);
skipWhitespaceIfAny(in);
files.push_back(s);
}
return files;
}
};
}