Input/Output 10: BufferedStream
The BufferedStream class is used to wrap a Stream object and supports buffering to improve performance. There are two constructors that you can use to create a BufferedStream object. The first one accepts a Stream object. The BufferedStream object constructed using this constructor has a buffer size of 4,096 bytes. The second constructor accepts a Stream object as well as an Integer specifying the size of the buffer, allowing you to set your own buffer size.
As an example of how to use the BufferedStream, consider the following code, which wraps the Stream object returned from an OpenFileDialog in a BufferedStream object and reads the first 128 bytes of the selected file:
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
string filepath = openFileDialog.FileName;
// Open the file using the OpenFile method
BufferedStream bufferedStream = new BufferedStream(
Byte bytes = new Byte;
bufferedStream.Read(bytes, 0, 128);
Note that the BufferedStream class is derived from the Stream class; therefore, it inherits all of the Stream class' methods and properties.
Feel free to comment this article using a facebook profile.
I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.