我使用第三方DLL创建私有FileStream并将内容写入其中。
我使用反射访问该流,我真的需要从流中复制字节。
writer.Write(buffer, 0, bytesRecorded); //writer is the instance of class defined in DLL
FieldInfo fi_out_stream = writer.GetType().GetField("outStream", BindingFlags.NonPublic | BindingFlags.Instance);
FileStream outStream = (FileStream)fi_out_stream.GetValue(writer);
FieldInfo fi_data_size_pos = writer.GetType().GetField("dataSizePos", BindingFlags.NonPublic | BindingFlags.Instance);
Int64 dataSizePos = (Int64)fi_data_size_pos.GetValue(writer);
if (this.CurrentWaveMS == null) //this is MemoryStream where I want to store bytes from outStream
{
this.CurrentWaveMS = new MemoryStream();
outStream.CopyTo(this.CurrentWaveMS); //getting read not supported exception here
}
else
{
long curr_pos = outStream.Position;
long diff = outStream.Length - this.CurrentWaveMS.Length;
byte[] buff = new byte[diff];
outStream.Position -= diff;
outStream.Read(buff, 0, (int)diff); //and here
outStream.Position = curr_pos;
this.CurrentWaveMS.Write(buff, 0, buff.Length);
}
我需要复制outStream
。是否有任何技巧来访问存储在流中的字节?