void mitk::ExampleDataStructureWriterService::Write() { MITK_INFO << "Writing ExampleDataStructure"; InputType::ConstPointer input = dynamic_cast<const InputType *>(this->GetInput()); if (input.IsNull()) { MITK_ERROR << "Sorry, input to ExampleDataStructureWriterService is nullptr!"; return; } if (this->GetOutputLocation().empty()) { MITK_ERROR << "Sorry, filename has not been set!"; return; } std::string ext = itksys::SystemTools::GetFilenameLastExtension(this->GetOutputLocation()); ext = itksys::SystemTools::LowerCase(ext); // default extension is .txt if (ext == "") { ext = ".txt"; this->SetOutputLocation(this->GetOutputLocation() + ext); } try { std::ofstream file(this->GetOutputLocation()); if (file.is_open()) { file << input->GetData(); } else { mitkThrow() << "Could not open file " << this->GetOutputLocation() << " for writing."; } MITK_INFO << "Example Data Structure has been written"; } catch (mitk::Exception e) { MITK_ERROR << e.GetDescription(); } catch (...) { MITK_ERROR << "Unknown error occurred while trying to write file."; } }