IBR-DTNSuite 0.6

ibrcommon/ibrcommon/data/Base64Stream.h

Go to the documentation of this file.
00001 /*
00002  * Base64Stream.h
00003  *
00004  *  Created on: 16.06.2011
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef BASE64STREAM_H_
00009 #define BASE64STREAM_H_
00010 
00011 #include <iostream>
00012 #include <streambuf>
00013 #include <stdint.h>
00014 
00015 namespace ibrcommon
00016 {
00017         class Base64Stream : public std::basic_streambuf<char, std::char_traits<char> >, public std::ostream
00018         {
00019         public:
00020                 Base64Stream(std::ostream &stream, bool decode = false, const size_t linebreak = 0, const size_t buffer = 2048);
00021                 virtual ~Base64Stream();
00022 
00023         protected:
00024                 virtual int sync();
00025                 virtual int overflow(int = std::char_traits<char>::eof());
00026 
00027         private:
00028                 static const char encodeCharacterTable[];
00029                 static const char decodeCharacterTable[];
00030 
00031                 bool _decode;
00032 
00033                 std::ostream &_stream;
00034 
00035                 // Output buffer
00036                 char *data_buf_;
00037 
00038                 // length of the data buffer
00039                 size_t data_size_;
00040 
00041                 uint8_t _base64_state;
00042 
00043                 size_t _char_counter;
00044 
00045                 char _base64_buf[4];
00046                 char _base64_padding;
00047 
00048                 size_t _linebreak;
00049         };
00050 }
00051 
00052 #endif /* BASE64STREAM_H_ */