2011-11-18 20:17:27 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
#include <DB/IO/ReadBufferFromHTTP.h>
|
|
|
|
|
#include "ReadHelpers.h"
|
2011-11-18 20:17:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
/** Позволяет читать файл с удалённого сервера через riod.
|
2011-11-18 20:17:27 +00:00
|
|
|
|
*/
|
|
|
|
|
class RemoteReadBuffer : public ReadBuffer
|
|
|
|
|
{
|
|
|
|
|
private:
|
2014-03-21 17:23:09 +00:00
|
|
|
|
Poco::SharedPtr<ReadBufferFromHTTP> impl;
|
2011-11-18 20:17:27 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2012-01-30 19:18:25 +00:00
|
|
|
|
RemoteReadBuffer(
|
2014-03-21 17:23:09 +00:00
|
|
|
|
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)
|
2011-11-18 20:17:27 +00:00
|
|
|
|
{
|
|
|
|
|
std::string encoded_path;
|
|
|
|
|
Poco::URI::encode(path, "&#", encoded_path);
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
std::stringstream params;
|
|
|
|
|
params << "action=read&path=" << encoded_path << "&compress=" << (compress ? "true" : "false");
|
2011-11-18 20:17:27 +00:00
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
impl = new ReadBufferFromHTTP(host, port, params.str, timeout, buffer_size);
|
2011-11-18 20:17:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool nextImpl()
|
|
|
|
|
{
|
|
|
|
|
if (!impl->next())
|
|
|
|
|
return false;
|
|
|
|
|
internal_buffer = impl->buffer();
|
|
|
|
|
working_buffer = internal_buffer;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
/// Вернуть список имен файлов в директории.
|
|
|
|
|
static std::vector<std::string> listFiles(
|
|
|
|
|
const std::string & host,
|
|
|
|
|
int port,
|
|
|
|
|
const std::string & path,
|
2014-03-21 17:23:09 +00:00
|
|
|
|
size_t timeout = 0)
|
2013-12-13 12:53:17 +00:00
|
|
|
|
{
|
|
|
|
|
std::string encoded_path;
|
|
|
|
|
Poco::URI::encode(path, "&#", encoded_path);
|
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
std::stringstream params;
|
|
|
|
|
params << "action=list&path=" << encoded_path;
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
2014-03-21 17:23:09 +00:00
|
|
|
|
ReadBufferFromHTTP in(host, port, params.str(), timeout);
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
std::vector<std::string> files;
|
2014-03-21 17:23:09 +00:00
|
|
|
|
while (!in.eof())
|
|
|
|
|
{
|
|
|
|
|
std::string s;
|
|
|
|
|
readString(s, in);
|
|
|
|
|
skipWhitespaceIfAny(in);
|
2013-12-13 12:53:17 +00:00
|
|
|
|
files.push_back(s);
|
2014-03-21 17:23:09 +00:00
|
|
|
|
}
|
2013-12-13 12:53:17 +00:00
|
|
|
|
|
|
|
|
|
return files;
|
|
|
|
|
}
|
2011-11-18 20:17:27 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|