| 242 | } |
| 243 | |
| 244 | void ProcessSession::append(const std::shared_ptr<core::FlowFile> &flow, OutputStreamCallback *callback) { |
| 245 | std::shared_ptr<ResourceClaim> claim = flow->getResourceClaim(); |
| 246 | if (!claim) { |
| 247 | // No existed claim for append, we need to create new claim |
| 248 | return write(flow, callback); |
| 249 | } |
| 250 | |
| 251 | try { |
| 252 | uint64_t startTime = utils::timeutils::getTimeMillis(); |
| 253 | std::shared_ptr<io::BaseStream> stream = content_session_->write(claim, ContentSession::WriteMode::APPEND); |
| 254 | if (nullptr == stream) { |
| 255 | throw Exception(FILE_OPERATION_EXCEPTION, "Failed to open flowfile content for append"); |
| 256 | } |
| 257 | // Call the callback to write the content |
| 258 | |
| 259 | size_t oldPos = stream->size(); |
| 260 | // this prevents an issue if we write, above, with zero length. |
| 261 | if (oldPos > 0) |
| 262 | stream->seek(oldPos + 1); |
| 263 | if (callback->process(stream) < 0) { |
| 264 | throw Exception(FILE_OPERATION_EXCEPTION, "Failed to process flowfile content"); |
| 265 | } |
| 266 | flow->setSize(stream->size()); |
| 267 | |
| 268 | std::stringstream details; |
| 269 | details << process_context_->getProcessorNode()->getName() << " modify flow record content " << flow->getUUIDStr(); |
| 270 | uint64_t endTime = utils::timeutils::getTimeMillis(); |
| 271 | provenance_report_->modifyContent(flow, details.str(), endTime - startTime); |
| 272 | } catch (std::exception &exception) { |
| 273 | logger_->log_debug("Caught Exception %s", exception.what()); |
| 274 | throw; |
| 275 | } catch (...) { |
| 276 | logger_->log_debug("Caught Exception during process session append"); |
| 277 | throw; |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | int ProcessSession::read(const std::shared_ptr<core::FlowFile> &flow, InputStreamCallback *callback) { |
| 282 | try { |
no test coverage detected