blob: a671677d76bb0622d3c82b6f404bad1410198ad9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "fileconfigsnapshotreader.h"
#include "jsonconfigformatter.h"
#include <vespa/config/common/exceptions.h>
#include <fstream>
#include <sstream>
namespace config {
FileConfigSnapshotReader::FileConfigSnapshotReader(const vespalib::string & fileName)
: _fileName(fileName)
{
}
ConfigSnapshot
FileConfigSnapshotReader::read()
{
std::ifstream file(_fileName.c_str());
if (!file.is_open())
throw ConfigReadException("error: unable to read file '%s'", _fileName.c_str());
std::stringstream buf;
buf << file.rdbuf();
ConfigDataBuffer buffer;
buffer.setEncodedString(buf.str());
JsonConfigFormatter formatter(true);
formatter.decode(buffer);
ConfigSnapshot snapshot;
snapshot.deserialize(buffer);
return snapshot;
}
} // namespace config
|