Botan  1.10.9
data_snk.cpp
Go to the documentation of this file.
1 /*
2 * DataSink
3 * (C) 1999-2007 Jack Lloyd
4 * 2005 Matthew Gregan
5 *
6 * Distributed under the terms of the Botan license
7 */
8 
9 #include <botan/data_snk.h>
10 #include <botan/exceptn.h>
11 #include <fstream>
12 
13 namespace Botan {
14 
15 /*
16 * Write to a stream
17 */
18 void DataSink_Stream::write(const byte out[], size_t length)
19  {
20  sink.write(reinterpret_cast<const char*>(out), length);
21  if(!sink.good())
22  throw Stream_IO_Error("DataSink_Stream: Failure writing to " +
23  identifier);
24  }
25 
26 /*
27 * DataSink_Stream Constructor
28 */
30  const std::string& name) :
31  identifier(name),
32  sink_p(0),
33  sink(out)
34  {
35  }
36 
37 /*
38 * DataSink_Stream Constructor
39 */
40 DataSink_Stream::DataSink_Stream(const std::string& path,
41  bool use_binary) :
42  identifier(path),
43  sink_p(new std::ofstream(
44  path.c_str(),
45  use_binary ? std::ios::binary : std::ios::out)),
46  sink(*sink_p)
47  {
48  if(!sink.good())
49  {
50  delete sink_p;
51  throw Stream_IO_Error("DataSink_Stream: Failure opening " + path);
52  }
53  }
54 
55 /*
56 * DataSink_Stream Destructor
57 */
59  {
60  delete sink_p;
61  }
62 
63 }
Definition: secmem.h:422
unsigned char byte
Definition: types.h:22
DataSink_Stream(std::ostream &stream, const std::string &name="<std::ostream>")
Definition: data_snk.cpp:29
void write(const byte[], size_t)
Definition: data_snk.cpp:18