Streams

C

Chris

I'm reading up on streams and I have two articles that
seem to conflict with each other. One article describes
streams and lists a few of the major ones (FileStream,
Memory Stream, Network Stream, etc.). It then goes on to
discuss the restriction that streams only read bytes or
byte arrays that the .net framework provides a
StreamReader and StreamWriter class to do type conversions
to and from bytes when using streams.
The second article describes the StreamReader and
StreamWriter class as streams themselves and demonstrates
them using the File class object to open a file and
read/write to it using the returned StreamReader and
StreamWriter objects of the static file methods.

So what is technically correct? Are the StreamReader and
StreamWriter classes actually streams or just wrapper
classes for converting data to and from bytes? Do we
actaully ever deal with streams directly or is it our use
of the StreamReader and StreamWriter that gives us access
to the "actual" stream objects?

I hope this is an interesting thought for someone to
ponder.
Thanks, Chris
 
J

Jay B. Harlow [MVP - Outlook]

Chris,
The way I view it is to be considered a "Stream" you need to inherit from
System.IO.Stream. As this allows you to use one of these objects where ever
you can use a Stream object.

FileStream, MemoryStream, NetworkStream all inherit from System.IO.Stream so
they are streams.
So what is technically correct? Are the StreamReader and
StreamWriter classes actually streams or just wrapper
classes for converting data to and from bytes?
StreamReader & StreamWriter are wrapper classes for converting streams to &
from 'text'.

BinaryReader & BinaryWriter are wrapper classes for converting streams to &
from 'binary'. These are useful when you want to read & write the actual
bits not a Text file.
Do we
actaully ever deal with streams directly or is it our use
of the StreamReader and StreamWriter that gives us access
to the "actual" stream objects?
Yes I deal with streams directly. And yes I user StreamReader & StreamWriter
to give me access to actual stream objects. I also use BinaryReader &
BinaryWriter to give me access to actual stream objects.

It really depends on what I am doing & trying to accomplish. Most of the
time I use either pair of Reader/Writer classes (stream & binary). If I am
doing serialization or some very specific stream stuff I use the stream
class itself.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top