diff 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
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Tue Jul 16 11:30:24 2013 +0200
+++ b/Core/Toolbox.cpp	Tue Jul 16 12:01:39 2013 +0200
@@ -208,10 +208,10 @@
                          const std::string& path) 
   {
     boost::filesystem::ifstream f;
-    f.open(path, std::ifstream::in | std::ios::binary);
+    f.open(path, std::ifstream::in | std::ifstream::binary);
     if (!f.good())
     {
-      throw OrthancException("Unable to open a file");
+      throw OrthancException(ErrorCode_InexistentFile);
     }
 
     // http://www.cplusplus.com/reference/iostream/istream/tellg/
@@ -229,6 +229,26 @@
   }
 
 
+  void Toolbox::WriteFile(const std::string& content,
+                          const std::string& path)
+  {
+    boost::filesystem::ofstream f;
+    f.open(path, std::ofstream::binary);
+    if (!f.good())
+    {
+      throw OrthancException(ErrorCode_CannotWriteFile);
+    }
+
+    if (content.size() != 0)
+    {
+      f.write(content.c_str(), content.size());
+    }
+
+    f.close();
+  }
+
+
+
   void Toolbox::RemoveFile(const std::string& path)
   {
     if (boost::filesystem::exists(path))