Mercurial > hg > orthanc
comparison Core/Toolbox.cpp @ 483:8c3573d28868
export dicom instances to the filesystem
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 16 Jul 2013 12:01:39 +0200 |
parents | 6f8ae46ed90e |
children | b22312081388 69c024f9c06b 3f27814104f7 |
comparison
equal
deleted
inserted
replaced
482:b05eb8708aee | 483:8c3573d28868 |
---|---|
206 | 206 |
207 void Toolbox::ReadFile(std::string& content, | 207 void Toolbox::ReadFile(std::string& content, |
208 const std::string& path) | 208 const std::string& path) |
209 { | 209 { |
210 boost::filesystem::ifstream f; | 210 boost::filesystem::ifstream f; |
211 f.open(path, std::ifstream::in | std::ios::binary); | 211 f.open(path, std::ifstream::in | std::ifstream::binary); |
212 if (!f.good()) | 212 if (!f.good()) |
213 { | 213 { |
214 throw OrthancException("Unable to open a file"); | 214 throw OrthancException(ErrorCode_InexistentFile); |
215 } | 215 } |
216 | 216 |
217 // http://www.cplusplus.com/reference/iostream/istream/tellg/ | 217 // http://www.cplusplus.com/reference/iostream/istream/tellg/ |
218 f.seekg(0, std::ios::end); | 218 f.seekg(0, std::ios::end); |
219 std::streamsize size = f.tellg(); | 219 std::streamsize size = f.tellg(); |
225 f.read(reinterpret_cast<char*>(&content[0]), size); | 225 f.read(reinterpret_cast<char*>(&content[0]), size); |
226 } | 226 } |
227 | 227 |
228 f.close(); | 228 f.close(); |
229 } | 229 } |
230 | |
231 | |
232 void Toolbox::WriteFile(const std::string& content, | |
233 const std::string& path) | |
234 { | |
235 boost::filesystem::ofstream f; | |
236 f.open(path, std::ofstream::binary); | |
237 if (!f.good()) | |
238 { | |
239 throw OrthancException(ErrorCode_CannotWriteFile); | |
240 } | |
241 | |
242 if (content.size() != 0) | |
243 { | |
244 f.write(content.c_str(), content.size()); | |
245 } | |
246 | |
247 f.close(); | |
248 } | |
249 | |
230 | 250 |
231 | 251 |
232 void Toolbox::RemoveFile(const std::string& path) | 252 void Toolbox::RemoveFile(const std::string& path) |
233 { | 253 { |
234 if (boost::filesystem::exists(path)) | 254 if (boost::filesystem::exists(path)) |