00001 /* Copyright (c) 2006, Gennady Bystritsky <bystr@mac.com> 00002 * 00003 * Distributed under the MIT Licence. 00004 * This is free software. See 'LICENSE' for details. 00005 * You must read and accept the license prior to use. 00006 */ 00007 00008 #ifndef _SK_IO_BUFFEREDOUTPUTSTREAM_ 00009 #define _SK_IO_BUFFEREDOUTPUTSTREAM_ 00010 00011 #include <sk/io/DelegatingOutputStream.h> 00012 #include <vector> 00013 00014 namespace sk { 00015 namespace io { 00016 class BufferedOutputStream 00017 : public DelegatingOutputStream 00018 { 00019 public: 00020 BufferedOutputStream(sk::io::OutputStream& stream); 00021 BufferedOutputStream(sk::io::OutputStream& stream, int size); 00022 virtual ~BufferedOutputStream(); 00023 00024 // sk::util::Object re-implementation. 00025 const sk::util::Class getClass() const; 00026 00027 // sk::io::DelegatingOutputStream re-implemenation. 00028 void flush(); 00029 void close(); 00030 int write(const char* buffer, int offset, int size); 00031 using DelegatingOutputStream::write; 00032 00033 private: 00034 BufferedOutputStream(const BufferedOutputStream& other); 00035 BufferedOutputStream& operator = (const BufferedOutputStream& other); 00036 00037 void flushChunks(int chunk_size); 00038 00039 int _size; 00040 std::vector<char> _buffer; 00041 }; 00042 } 00043 } 00044 00045 #endif /* _SK_IO_BUFFEREDOUTPUTSTREAM_ */