Botan
1.11.15
|
00001 /* 00002 * DataSink 00003 * (C) 1999-2007 Jack Lloyd 00004 * 2005 Matthew Gregan 00005 * 00006 * Botan is released under the Simplified BSD License (see license.txt) 00007 */ 00008 00009 #include <botan/data_snk.h> 00010 #include <botan/exceptn.h> 00011 #include <fstream> 00012 00013 namespace Botan { 00014 00015 /* 00016 * Write to a stream 00017 */ 00018 void DataSink_Stream::write(const byte out[], size_t length) 00019 { 00020 sink.write(reinterpret_cast<const char*>(out), length); 00021 if(!sink.good()) 00022 throw Stream_IO_Error("DataSink_Stream: Failure writing to " + 00023 identifier); 00024 } 00025 00026 /* 00027 * DataSink_Stream Constructor 00028 */ 00029 DataSink_Stream::DataSink_Stream(std::ostream& out, 00030 const std::string& name) : 00031 identifier(name), 00032 sink_p(nullptr), 00033 sink(out) 00034 { 00035 } 00036 00037 /* 00038 * DataSink_Stream Constructor 00039 */ 00040 DataSink_Stream::DataSink_Stream(const std::string& path, 00041 bool use_binary) : 00042 identifier(path), 00043 sink_p(new std::ofstream( 00044 path.c_str(), 00045 use_binary ? std::ios::binary : std::ios::out)), 00046 sink(*sink_p) 00047 { 00048 if(!sink.good()) 00049 { 00050 delete sink_p; 00051 throw Stream_IO_Error("DataSink_Stream: Failure opening " + path); 00052 } 00053 } 00054 00055 /* 00056 * DataSink_Stream Destructor 00057 */ 00058 DataSink_Stream::~DataSink_Stream() 00059 { 00060 delete sink_p; 00061 } 00062 00063 }