I am receiving System IO Streams from a source. I will proceed with the stream object only if it contains the string "MSTND"
.
I realize there is not much I can do on the stream unless I convert it into string. The string conversion is only for sub-string matching. But I don't want to do anything that takes up lot of time or space. How time / space intensive is a conversion from Stream to string just for sub-string matching?
The code I have written is:
private bool StreamHasString (Stream vStream)
{
bool containsStr = false;
byte[] streamBytes = new byte[vStream.Length];
vStream.Read( streamBytes, 0, (int) vStream.Length);
string stringOfStream = Encoding.UTF32.GetString(streamBytes);
if (stringOfStream.Contains("MSTND"))
{
containsStr = true;
}
return containsStr ;
}