stream position on OutputResolver stream
I implemented an OutputResolver class to intercept xsl:result-documents and direct their output to a stream via a Serializer destination. I'm running into an issue where the stream position is at the end of the stream after the serializing is finished. Is this the expected behavior? Is there a way to set the position back to 0? I'm wrapping this up in a DLL in my code library, and I'd like for the stream returned to the calling applications to be set up for an immediate read, rather than expecting the calling application to reposition it to the beginning.
I'm using HE 10.2.0 for .NET. Relevant code is below.
ecmVFile is a class from a different internal code library, which essentially wrappers a stream along with some additional properties like a file name and extension for when the stream is eventually written to file. I can likely reset the stream position there if needed, but was hoping to accomplish it here instead.
Friend Function HandleResultDocument(href As String, baseUri As Uri) As XmlDestination Implements IResultDocumentHandler.HandleResultDocument
mLog.BufferLog("handling result document. href = " & href, 4) Dim p As New Processor Dim mySerializer As Serializer = p.NewSerializer Dim myUri As New Uri(href, UriKind.RelativeOrAbsolute) If myUri.IsAbsoluteUri Then mLog.BufferLog("href indicates an absolute path. writing result to physical file and adding URI to physical file URI list.", 4) mySerializer.SetOutputFile(myUri.LocalPath) physicalSecondaryOutputURIs.Add(myUri.LocalPath) Else mLog.BufferLog("href indicates a relative path. writing result to stream and adding to vfile list.", 4) Dim myStream As New System.IO.MemoryStream mySerializer.SetOutputStream(myStream) Dim myFileName As String Dim myExtension As String If href.Contains(".") Then myFileName = href.Substring(0, href.LastIndexOf(".")) myExtension = href.Substring(href.LastIndexOf(".") + 1) Else myFileName = href myExtension = "" End If Dim myFile As New ecmVFile(, myStream,,, myFileName, myExtension) virtualSecondaryOutputFiles.Add(myFile) End If Return mySerializer End Function
Apologies if I've posted this in the wrong spot, but I didn't want to post it in the issues forum since I suspect it's expected behavior.
RE: stream position on OutputResolver stream - Added by Michael Kay 2 months ago
My immediate thought is that changing the behaviour could be disruptive to existing users: if they are expecting to append to the stream after it has been written, then repositioning to the start would be bad news.
RE: stream position on OutputResolver stream - Added by Erica Coan 2 months ago
That makes sense. I'll look into repositioning on my side, or using a TextWriter instead of the MemoryStream. Thank you!
Please register to reply