monotone

monotone Mtn Source Tree

Root/botan/data_snk.cpp

1/*************************************************
2* DataSink Source File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#include <botan/data_snk.h>
7#include <fstream>
8
9namespace Botan {
10
11/*************************************************
12* Write to a stream *
13*************************************************/
14void DataSink_Stream::write(const byte out[], u32bit length)
15 {
16 sink->write((const char*)out, length);
17 if(!sink->good())
18 throw Stream_IO_Error("DataSink_Stream: Failure writing to " + fsname);
19 }
20
21/*************************************************
22* DataSink_Stream Constructor *
23*************************************************/
24DataSink_Stream::DataSink_Stream(std::ostream& stream) : fsname("std::ostream")
25 {
26 sink = &stream;
27 owns = false;
28 }
29
30/*************************************************
31* DataSink_Stream Constructor *
32*************************************************/
33DataSink_Stream::DataSink_Stream(const std::string& file,
34 bool use_binary) : fsname(file)
35 {
36 if(use_binary)
37 sink = new std::ofstream(fsname.c_str(), std::ios::binary);
38 else
39 sink = new std::ofstream(fsname.c_str());
40
41 if(!sink->good())
42 throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname);
43 owns = true;
44 }
45
46/*************************************************
47* DataSink_Stream Destructor *
48*************************************************/
49DataSink_Stream::~DataSink_Stream()
50 {
51 if(owns)
52 delete sink;
53 sink = 0;
54 }
55
56}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status