· Jun 20

How to Transform a String into a Stream in Interoperability Production?

Hi folks!

I have an example where I want to write a string into a file.

I have a message with string and I want to write the string down into a file.

I took EnsLib.FilePathThrough.Operation which expects Ens.StreamContainer message.

So I perform a data transformation where I need to transfer string to a stream. Here is the DataTransformation:

And on the second step there is an ObjectScript code:

As you could notice, this is not an obvious transformation. Indeed, first I ought to create an instance of Stream object.

Then I'm running an ObjectScript which writes string to Stream. Notice a space(" ") symbol as the first symbol of the code line. Is it obvious?

And this works.

Question: is there a simpler way to perform such a transformation from the string to a stream?

What I have in mind is that I derive from EnsLib.FilePathThrough.Operation into a new message class where I add a string property which I can initialize with the string. And then the operation will take the data from string and write it to file. Or init the stream by itself with this string in once created.


Product version: IRIS 2023.1
Discussion (4)1
Log in or sign up to continue

Hi Evgeny,

An option is to use a FunctionSet, for example:

 Class Test.Str2Stream Extends Ens.Rule.FunctionSet
{ ClassMethod StringToStream(initValue As %String = "undefined", filename As %String = "") As %GlobalCharacterStream
set ret=##class(%GlobalCharacterStream).%New()
set ret.Attributes("Filename")=filename
do ret.Write(initValue)
quit ret

This will let you see the nice single line "From Source property" and "To Target Property"

Where assignment value was:


The Gotcha

If you have a test form input message:

  <Content>ho ho ho</Content>

And this is not populating output like:

  <Stream><![CDATA[ho ho ho]</Stream>

Then go back and check the input message type extends %XML.Adaptor.

 Class Test.Str2Stream.ExampleIn Extends (%Persistent, %XML.Adaptor)

ie: It is a limitation of the Test form that it expects to be able to correlate the content from XML to Test Object.

Hope this helps.