我在控制台程序中编写了一些代码,并使用文件进行了测试。
现在我想将它移植到实现特定接口的 BizTalk Pipeline 组件中。我不知道从文件到内存流的
那么现在,如何最好地更改我的测试代码以使其写入内存流呢?考虑到我有很多 .WriteLine 语句,我可以先写入 StringBuffer,但我认为这将破坏流式传输的概念(即一次在内存中具有整个文档)。
.Write
和 .WriteLine
方法之间有这么大的差异。我原以为只需交换对象即可。但是,这里没有 .WriteLine
方法,而且 .Write 方法需要偏移量和字节(额外参数)。那么现在,如何最好地更改我的测试代码以使其写入内存流呢?考虑到我有很多 .WriteLine 语句,我可以先写入 StringBuffer,但我认为这将破坏流式传输的概念(即一次在内存中具有整个文档)。
// This is how I used the streams in the Console program
//FileStream originalStream = File.Open(inFilename, FileMode.Open);
//StreamWriter streamToReturn = new StreamWriter(outFilename);
// This is how to get the input stream in the BizTalk Pipeline Componenet
System.IO.Stream originalStream = pInMsg.BodyPart.GetOriginalDataStream();
MemoryStream streamToReturn = new MemoryStream();
streamToReturn.WriteLine("<" + schemaStructure.rootElement + ">");
这里没有展示所有的代码。上面只是为了讲述我所做的事情。
StreamWriter
需要刷新到它正在写入的底层Stream
。 - Igor