Streams contents

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Do the stream objects in .NET support any tipe of content i'd like to put in
them?, like memorystream...can i put a table in there? or a stream inside
another stream?
 
VBA said:
Do the stream objects in .NET support any tipe of content i'd like to put
in
them?, like memorystream...can i put a table in there? or a stream inside
another stream?

You always Read or Write arrays of bytes into the Stream objects. You
can put inside anything that you want, as long as you know how to convert it
to/from an array of bytes; the Stream will not do the conversion for you.

One object that "knows" how to do such a conversion is a Formatter (such
as the BinaryFormatter and the SoapFormatter). These formatters take an
arbitrary object, on the condition that it be Serializable, and then write a
representation of the object into a Stream.

A Stream "inside" another Stream doesn't make much sense. What you
sometimes have to do is connect the output of a Stream to the input of
another one. This happens, for instance, when you want to encrypt something
into a file: you connect a CryptoStream with a FileStream. The CryptoStream
receives an array of bytes, and the FileStream writes another array of bytes
into the file.
 
Just a clarification; streams are pipes not buckets. Typically a
stream doesn't "contain" anything - it is merely a connector to
something else (just as the file-system or a database), or to several
other pipes (i.e. a compression stream linked to a network stream
perhaps).

MemoryStream is a bit of an exception, but in general you should treat
streams like, er, pipes. So: you can't place a stream inside another -
but you can pump data from one stream into another, or some streams
allow you to connect them end to end (usually in the constructor).

Marc
 
Ok, now i have a better idea on how to work with streams

Thanks both of you!! :)
 

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

Back
Top