diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
commit | 9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch) | |
tree | 63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/filters/data_snk.cpp | |
parent | 619d92cfef29e653bfdf852e83888e50cfc4348f (diff) | |
parent | 65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/filters/data_snk.cpp')
-rw-r--r-- | botan/src/filters/data_snk.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/botan/src/filters/data_snk.cpp b/botan/src/filters/data_snk.cpp new file mode 100644 index 0000000..f8ee9f8 --- /dev/null +++ b/botan/src/filters/data_snk.cpp @@ -0,0 +1,62 @@ +/* +* DataSink +* (C) 1999-2007 Jack Lloyd +* 2005 Matthew Gregan +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/data_snk.h> +#include <botan/exceptn.h> +#include <fstream> + +namespace Botan { + +/* +* Write to a stream +*/ +void DataSink_Stream::write(const byte out[], u32bit length) + { + sink->write(reinterpret_cast<const char*>(out), length); + if(!sink->good()) + throw Stream_IO_Error("DataSink_Stream: Failure writing to " + + identifier); + } + +/* +* DataSink_Stream Constructor +*/ +DataSink_Stream::DataSink_Stream(std::ostream& out, + const std::string& name) : + identifier(name != "" ? name : "<std::ostream>"), owner(false) + { + sink = &out; + } + +/* +* DataSink_Stream Constructor +*/ +DataSink_Stream::DataSink_Stream(const std::string& path, + bool use_binary) : + identifier(path), owner(true) + { + if(use_binary) + sink = new std::ofstream(path.c_str(), std::ios::binary); + else + sink = new std::ofstream(path.c_str()); + + if(!sink->good()) + throw Stream_IO_Error("DataSink_Stream: Failure opening " + path); + } + +/* +* DataSink_Stream Destructor +*/ +DataSink_Stream::~DataSink_Stream() + { + if(owner) + delete sink; + sink = 0; + } + +} |