This stream acts as a cache. It caches the bytes to be written to the specified
output stream (See \helpref{wxFilterOutputStream}{wxfilteroutputstream}). The
-datas are only written when the cache is full or when the buffered stream is
-destroyed.
+datas are only written when the cache is full, when the buffered stream is
+destroyed or when calling SeekO().
+
This class may not be used without some other stream to write the data
to (such as a file stream or a memory stream).
\helpref{wxStreamBuffer}{wxstreamBuffer}, \helpref{wxOutputStream}{wxoutputstream}
+% ----------
+% Members
+% ----------
+\latexignore{\rtfignore{\wxheading{Members}}}
+
+\membersection{wxBufferedOutputStream::wxBufferedOutputStream}
+
+\func{}{wxBufferedOutputStream}{\param{const wxOutputStream\&}{ parent}}
+
+Creates a buffered stream using a buffer of a default size of 1024 bytes for cashing
+the stream {\it parent}.
+
+\membersection{wxBufferedOutputStream::\destruct{wxBufferedOutputStream}}
+
+\func{}{\destruct{wxBufferedOutputStream}}{\void}
+
+Destructor. Calls Sync() and destroys the internal buffer.
+
+\membersection{wxBufferedOutputStream::SeekO}
+
+\func{off\_t}{SeekO}{\param{off\_t}{ pos}, \param{wxSeekMode}{ mode}}
+
+Calls Sync() and changes the stream position.
+
+\membersection{wxBufferedOutputStream::Sync}
+
+\func{void}{Sync}{\void}
+
+Flushes the buffer and calls Sync() on the parent stream.
+
+
+
#if wxUSE_UNICODE
EVT_MENU(TYPES_UNICODE, MyApp::DoUnicodeDemo)
#endif
+ EVT_MENU(TYPES_STREAM2, MyApp::DoStreamDemo2)
EVT_MENU(TYPES_STREAM, MyApp::DoStreamDemo)
EVT_MENU(TYPES_MIME, MyApp::DoMIMEDemo)
END_EVENT_TABLE()
test_menu->Append(TYPES_UNICODE, "&Unicode test");
#endif
test_menu->Append(TYPES_STREAM, "&Stream test");
+ test_menu->Append(TYPES_STREAM2, "&Stream seek test");
test_menu->AppendSeparator();
test_menu->Append(TYPES_MIME, "&MIME database test");
textCtrl.WriteText( tmp );
}
+void MyApp::DoStreamDemo2(wxCommandEvent& WXUNUSED(event))
+{
+ wxTextCtrl& textCtrl = * GetTextCtrl();
+
+ textCtrl.Clear();
+ textCtrl << _T("\nTest wxBufferedStream:\n\n");
+
+ char ch,ch2;
+
+ textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream:\n\n" );
+
+ wxFileOutputStream file_output( "test_wx.dat" );
+ wxBufferedOutputStream buf_output( file_output );
+ for (ch = 0; ch < 10; ch++)
+ buf_output.Write( &ch, 1 );
+ buf_output.Sync();
+
+ wxFileInputStream file_input( "test_wx.dat" );
+ for (ch2 = 0; ch2 < 10; ch2++)
+ {
+ file_input.Read( &ch, 1 );
+ textCtrl.WriteText( (char)(ch + '0') );
+ }
+ textCtrl.WriteText( "\n\n\n" );
+
+ textCtrl.WriteText( "Writing number 0 to 9 to buffered wxFileOutputStream, then\n" );
+ textCtrl.WriteText( "seeking back to #3 and writing 3:\n\n" );
+
+ wxFileOutputStream file_output2( "test_wx2.dat" );
+ wxBufferedOutputStream buf_output2( file_output2 );
+ for (ch = 0; ch < 10; ch++)
+ buf_output2.Write( &ch, 1 );
+ buf_output2.SeekO( 3 );
+ ch = 3;
+ buf_output2.Write( &ch, 1 );
+ buf_output2.Sync();
+
+ wxFileInputStream file_input2( "test_wx2.dat" );
+ for (ch2 = 0; ch2 < 10; ch2++)
+ {
+ file_input2.Read( &ch, 1 );
+ textCtrl.WriteText( (char)(ch + '0') );
+ }
+ textCtrl.WriteText( "\n\n\n" );
+
+ // now append 2000 bytes to file (bigger than buffer)
+ buf_output2.SeekO( 0, wxFromEnd );
+ ch = 1;
+ for (int i = 0; i < 2000; i++)
+ buf_output2.Write( &ch, 1 );
+ buf_output2.Sync();
+
+ textCtrl.WriteText( "Reading number 0 to 9 from buffered wxFileInputStream, then\n" );
+ textCtrl.WriteText( "seeking back to #3 and reading 3:\n\n" );
+
+ wxFileInputStream file_input3( "test_wx2.dat" );
+ wxBufferedInputStream buf_input3( file_input3 );
+ for (ch2 = 0; ch2 < 10; ch2++)
+ {
+ buf_input3.Read( &ch, 1 );
+ textCtrl.WriteText( (char)(ch + '0') );
+ }
+ for (int j = 0; j < 2000; j++)
+ buf_input3.Read( &ch, 1 );
+ textCtrl.WriteText( "\n" );
+ buf_input3.SeekI( 3 );
+ buf_input3.Read( &ch, 1 );
+ textCtrl.WriteText( (char)(ch + '0') );
+ textCtrl.WriteText( "\n\n\n" );
+
+}
+
#if wxUSE_UNICODE
void MyApp::DoUnicodeDemo(wxCommandEvent& WXUNUSED(event))
{
if (wxFileExists(filename))
{
wxFileInputStream stream(filename);
- return LoadFile(stream, type);
+ wxBufferedInputStream bstream( stream );
+ return LoadFile(bstream, type);
}
else
{
if (wxFileExists(filename))
{
wxFileInputStream stream(filename);
- return LoadFile(stream, mimetype);
+ wxBufferedInputStream bstream( stream );
+ return LoadFile(bstream, mimetype);
}
else
{
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
- return SaveFile(stream, type);
+ {
+ wxBufferedOutputStream bstream( stream );
+ return SaveFile(bstream, type);
+ }
else
#endif // wxUSE_STREAMS
return FALSE;
wxFileOutputStream stream(filename);
if ( stream.LastError() == wxStream_NOERROR )
- return SaveFile(stream, mimetype);
+ {
+ wxBufferedOutputStream bstream( stream );
+ return SaveFile(bstream, mimetype);
+ }
else
#endif // wxUSE_STREAMS
return FALSE;