· Sep 11

How to read and write values into Ens.StreamContainer

Hi Community,


I have SDA file as Ens.StreamContainer Message using pRequest As Ens.StreamContainer

SDA file structure looks like this 



How can i change individual value from the Steam and then save changed value into the stream?

Product version: IRIS 2022.3
$ZV: IRIS for Windows (x86-64) 2021.1.2 (Build 336_0_21564U) Tue Apr 12 2022 12:13:45 EDT
Discussion (3)3
Log in or sign up to continue

Hello smythe,

There are couple of ways to import your file into stream and convert to Ens.StreamContianer

First you can create a %FileCharacterStream object and link your file in to it. Create a streamcontainer object and send the created stream as a first parameter in %OnNew to Ens.StreamContiner class.

ClassMethod StreamContainer()
    set file="dir\file" ; Your directory and file name(C:\Intersystems\new13.txt)
    set file = ##class(%FileCharacterStream).%New()
    do file.LinkToFile(file)
    set strmContainer=##class(Ens.StreamContainer).%New(file)
    zwrite strmContainer.Stream.Read($$$MaxLocalLength)

Second, This way it's almost similar way. But Instead of pushing directly into Ens.Streamcontainer.  You need to create a object for SDA. Import your file through  XMLImportSDAString method to prepare SDA object.  Now you have SDA object handy. So you can do any SDA stuffs with this object. Eventually it's an implicit step for validate your SDA file structure(Keep in mind the file structure should be exact XML format of SDA). Once the SDA object generated you can use Stream method generate stream from this SDA. Now you can convert to Ens.StreamContainer. Refer the below code to implement the above steps

ClassMethod FileToSDAToEnsContainer()
    set file = ##class(%FileCharacterStream).%New()
    do file.LinkToFile("C:\FHIRFILE\new13.txt")
    set SDA3Container=##class(HS.SDA3.Container).%New()
    do SDA3Container.XMLImportSDAString(file.Read($$$MaxLocalLength))
    zwrite SDA3Container
    do SDA3Container.ToQuickXMLStream(.stream)
    set strmContainer=##class(Ens.StreamContainer).%New(stream)
    zwrite strmContainer.Stream.Read()