1

I'm reading data from a stream in buffered series of bytes (say 1024 bytes at a time) and do some comparison, checking, or processing, before writing it back to the same type of stream.

Currently data comes from file. But in the future it may come from other sources (memorymapped file, TCP etc)

Is there a design pattern I can implement? Or is that not necessary?

1 Answer 1

2

The .NET Framework provides the Stream abstract class for this purpose.

.NET offers a number of Stream Reader and Writer objects out of the box. One of those may already fit your needs, or you can inherit from Stream in a new class, and write your own custom implementation.

4
  • Can I just use Stream in place of an interface. So comsume a stream object, but when I actually pass it the object, it can be something a FileStream, or MemoryStream, and they will all work the same way.
    – erotavlas
    Commented Mar 26, 2014 at 17:46
  • 2
    @erotavlas: If they all share a common interface or superclass, and your variable's type is of that interface/class, then yes. That's exactly what interfaces and inheritance are made for.
    – cHao
    Commented Mar 26, 2014 at 18:41
  • That seems to be some COM interface, I've never seen it used in a .Net application. Instead, you should use the abstract Stream class.
    – svick
    Commented Mar 26, 2014 at 19:50
  • @svick: Oh, you know what? I think you're right. I always use one of the descendants of Stream, so I seldom think much about the base class. I'll edit to fix. Commented Mar 26, 2014 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.