| 103 | } |
| 104 | |
| 105 | std::unique_ptr<InputStream> readFile(const std::string& path, ReaderMetrics* metrics) { |
| 106 | #ifdef BUILD_LIBHDFSPP |
| 107 | if (strncmp(path.c_str(), "hdfs://", 7) == 0) { |
| 108 | return orc::readHdfsFile(std::string(path), metrics); |
| 109 | } else { |
| 110 | #endif |
| 111 | return orc::readLocalFile(std::string(path), metrics); |
| 112 | #ifdef BUILD_LIBHDFSPP |
| 113 | } |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | DIAGNOSTIC_POP |
| 118 | |
| 119 | std::unique_ptr<InputStream> readLocalFile(const std::string& path, ReaderMetrics* metrics) { |
| 120 | return std::make_unique<FileInputStream>(path, metrics); |
| 121 | } |
| 122 | |
| 123 | OutputStream::~OutputStream(){ |
| 124 | // PASS |
| 125 | }; |
| 126 | |
| 127 | class FileOutputStream : public OutputStream { |
| 128 | private: |
| 129 | std::string filename_; |
| 130 | int file_; |
| 131 | uint64_t bytesWritten_; |
| 132 | bool closed_; |
| 133 | |
| 134 | public: |
| 135 | FileOutputStream(std::string filename) { |
| 136 | bytesWritten_ = 0; |
| 137 | filename_ = filename; |
| 138 | closed_ = false; |
| 139 | file_ = open(filename_.c_str(), O_BINARY | O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR | S_IWUSR); |
| 140 | if (file_ == -1) { |
| 141 | throw ParseError("Can't open " + filename_); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | ~FileOutputStream() override; |
| 146 | |
| 147 | uint64_t getLength() const override { |
| 148 | return bytesWritten_; |
| 149 | } |
| 150 | |
| 151 | uint64_t getNaturalWriteSize() const override { |
| 152 | return 128 * 1024; |
| 153 | } |
| 154 | |
| 155 | void write(const void* buf, size_t length) override { |
| 156 | if (closed_) { |
| 157 | throw std::logic_error("Cannot write to closed stream."); |
| 158 | } |
| 159 | ssize_t bytesWrite = ::write(file_, buf, length); |
| 160 | if (bytesWrite == -1) { |
| 161 | throw ParseError("Bad write of " + filename_); |
| 162 | } |
no test coverage detected