Manipulating Streams
What's the proper way to do this? Assume I've got a stream of audio data and want to apply some audio filters to it before writing it to disk
What should the interface for the filters look like?
Sub Proc开发者_JAVA技巧ess(InputStream as IO.Stream)
or
Function Process(InputStream as IO.Stream) as IO.Stream
?
I suppose I'm a little unclear on how streams should be passed between classes and methods - Do I need to read the entire stream in a method, process it and then write to a new stream which is returned?
What about streams without a fixed length? I don't want to try and read a potentially infinite stream into memory - I want each filter to process a chunk and pass it on to the next filter.
Can someone please point me in the right direction?
Typically, I think of extending the functionality of Streams using the Decorator Pattern. In this case, one stream wraps the original and manipulates the data before passing it to the original stream's method. Check out this article from MSDN Magazine on creating an InterceptorStream
that provides additional functionality to the wrapped Stream
.
精彩评论