| 279 | } |
| 280 | |
| 281 | int ProcessSession::read(const std::shared_ptr<core::FlowFile> &flow, InputStreamCallback *callback) { |
| 282 | try { |
| 283 | std::shared_ptr<ResourceClaim> claim = nullptr; |
| 284 | |
| 285 | if (flow->getResourceClaim() == nullptr) { |
| 286 | // No existed claim for read, we throw exception |
| 287 | logger_->log_debug("For %s, no resource claim but size is %d", flow->getUUIDStr(), flow->getSize()); |
| 288 | if (flow->getSize() == 0) { |
| 289 | return 0; |
| 290 | } |
| 291 | throw Exception(FILE_OPERATION_EXCEPTION, "No Content Claim existed for read"); |
| 292 | } |
| 293 | |
| 294 | claim = flow->getResourceClaim(); |
| 295 | |
| 296 | std::shared_ptr<io::BaseStream> stream = content_session_->read(claim); |
| 297 | |
| 298 | if (nullptr == stream) { |
| 299 | throw Exception(FILE_OPERATION_EXCEPTION, "Failed to open flowfile content for read"); |
| 300 | } |
| 301 | |
| 302 | stream->seek(flow->getOffset()); |
| 303 | |
| 304 | auto ret = callback->process(stream); |
| 305 | if (ret < 0) { |
| 306 | throw Exception(FILE_OPERATION_EXCEPTION, "Failed to process flowfile content"); |
| 307 | } |
| 308 | return gsl::narrow<int>(ret); |
| 309 | } catch (std::exception &exception) { |
| 310 | logger_->log_debug("Caught Exception %s", exception.what()); |
| 311 | throw; |
| 312 | } catch (...) { |
| 313 | logger_->log_debug("Caught Exception during process session read"); |
| 314 | throw; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | void ProcessSession::importFrom(io::InputStream&& stream, const std::shared_ptr<core::FlowFile> &flow) { |
| 319 | importFrom(stream, flow); |
no test coverage detected