+// ----------------------------------------------------------------------------
+// wxBufferedInputStream
+// ----------------------------------------------------------------------------
+
+wxBufferedInputStream::wxBufferedInputStream(wxInputStream& s,
+ wxStreamBuffer *buffer)
+ : wxFilterInputStream(s)
+{
+ if ( buffer )
+ {
+ // use the buffer provided by the user
+ m_i_streambuf = buffer;
+ }
+ else // create a default buffer
+ {
+ m_i_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::read);
+
+ m_i_streambuf->SetBufferIO(1024);
+ }
+}
+
+wxBufferedInputStream::~wxBufferedInputStream()
+{
+ m_parent_i_stream->SeekI(-(off_t)m_i_streambuf->GetBytesLeft(),
+ wxFromCurrent);
+
+ delete m_i_streambuf;
+}
+
+char wxBufferedInputStream::Peek()
+{
+ return m_i_streambuf->Peek();
+}
+
+wxInputStream& wxBufferedInputStream::Read(void *buf, size_t size)
+{
+ size_t retsize;
+
+ retsize = GetWBack(buf, size);
+ m_lastcount = retsize;
+ if ( retsize == size )
+ {
+ m_lasterror = wxStream_NOERROR;
+ return *this;
+ }
+ size -= retsize;
+ buf = (char *)buf + retsize;
+
+ m_i_streambuf->Read(buf, size);
+
+ return *this;
+}
+
+off_t wxBufferedInputStream::SeekI(off_t pos, wxSeekMode mode)
+{
+ return m_i_streambuf->Seek(pos, mode);
+}
+
+off_t wxBufferedInputStream::TellI() const
+{
+ return m_i_streambuf->Tell();
+}
+
+size_t wxBufferedInputStream::OnSysRead(void *buffer, size_t bufsize)
+{
+ return m_parent_i_stream->Read(buffer, bufsize).LastRead();
+}
+
+off_t wxBufferedInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ return m_parent_i_stream->SeekI(seek, mode);
+}
+
+off_t wxBufferedInputStream::OnSysTell() const
+{
+ return m_parent_i_stream->TellI();
+}
+
+void wxBufferedInputStream::SetInputStreamBuffer(wxStreamBuffer *buffer)
+{
+ wxCHECK_RET( buffer, _T("wxBufferedInputStream needs buffer") );
+
+ delete m_i_streambuf;
+ m_i_streambuf = buffer;
+}
+
+// ----------------------------------------------------------------------------
+// wxBufferedOutputStream
+// ----------------------------------------------------------------------------
+
+wxBufferedOutputStream::wxBufferedOutputStream(wxOutputStream& s,
+ wxStreamBuffer *buffer)
+ : wxFilterOutputStream(s)
+{
+ if ( buffer )
+ {
+ m_o_streambuf = buffer;
+ }
+ else // create a default one
+ {
+ m_o_streambuf = new wxStreamBuffer(*this, wxStreamBuffer::write);
+
+ m_o_streambuf->SetBufferIO(1024);
+ }
+}
+
+wxBufferedOutputStream::~wxBufferedOutputStream()
+{
+ Sync();
+ delete m_o_streambuf;
+}
+
+wxOutputStream& wxBufferedOutputStream::Write(const void *buffer, size_t size)
+{
+ m_lastcount = 0;
+ m_o_streambuf->Write(buffer, size);
+ return *this;
+}
+
+off_t wxBufferedOutputStream::SeekO(off_t pos, wxSeekMode mode)
+{
+ Sync();
+ return m_o_streambuf->Seek(pos, mode);
+}
+
+off_t wxBufferedOutputStream::TellO() const
+{
+ return m_o_streambuf->Tell();
+}
+
+void wxBufferedOutputStream::Sync()
+{
+ m_o_streambuf->FlushBuffer();
+ m_parent_o_stream->Sync();
+}
+
+size_t wxBufferedOutputStream::OnSysWrite(const void *buffer, size_t bufsize)
+{
+ return m_parent_o_stream->Write(buffer, bufsize).LastWrite();
+}
+
+off_t wxBufferedOutputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ return m_parent_o_stream->SeekO(seek, mode);
+}
+
+off_t wxBufferedOutputStream::OnSysTell() const
+{
+ return m_parent_o_stream->TellO();
+}
+
+size_t wxBufferedOutputStream::GetSize() const
+{
+ return m_parent_o_stream->GetSize() + m_o_streambuf->GetIntPosition();
+}
+
+void wxBufferedOutputStream::SetOutputStreamBuffer(wxStreamBuffer *buffer)
+{
+ wxCHECK_RET( buffer, _T("wxBufferedOutputStream needs buffer") );
+
+ delete m_o_streambuf;
+ m_o_streambuf = buffer;
+}
+