Change Stream Property in Ens.StreamContainer with DTL
I'm trying to change the Stream property inside a DTL with a Source Class of Ens.StreamContainer. The code, below, will change it within the DTL testing tool, but running an actual message through the Production's Process doesn't change the Stream property. I can change other properties of Ens.StreamContainer by using the normal Set action and it is reflected when running it through the Process. For context, this uses a FTP service to grab a file. Any thoughts on why I can't just write modified stream data to the Stream property?
I use target here because I'm using the DTL copy function to preserve the OriginalFileName property.
| 1 | set | streamData | target.Stream.Read(target.Stream.Size) | "" | ||
| 2 | set | streamData | $REPLACE(streamData,"header1,header2"... | "" | ||
| 3 | code | do target.Stream.Write(streamData) |
Comments
How big (Size) is the stream? If it's larger then the maximum string supported string length (~3.5MB), then you have a problem with your code.
When it does not work, do you get an error?
In the DTL, how do you set the "Create" option/parameter? (copy or new?)
Is there any other reference/set referencing the Stream in the DTL?
Size of most files is about 100kb.
No errors on either the DTL testing tool or the Process's log.
I'm using the copy option.
The code is only there to remove a header, so those are the only three lines in this DTL.
Re problem with the code: the code works in the DTL testing tool, so I don't think the code is bad.
Just in case, try adding a "code" action BEFORE your actions with:
Do source.Stream.Rewind()
Do target.Stream.Clear()
I see what you're getting at and I tried this code with the same result.
Interestingly, the write() function seems to be overlaying the whole stream, not just writing over the existing one, as there aren't any extra/duplicate chars at the end of the stream. At least, not in the DTL testing tool.
"...the write() function seems to be overlaying the whole stream..."
Of course, that's the way a stream works as designed. The resulting (target) stream will contains what the Write() method writes to the stream. And only that.
If this is not what you expect, then please provide more details on your goal.
According to the doc, that doesn't seem to be the case, see reference below. Since I'm not reading the stream, it should start at byte 0 then overwrite the existing data. But, since the new data is smaller than the original, I would assume I should have duplicate data at the end. For w/e reason, I don't.
But this is kind of off topic as this isn't really my issue; the data looks correct. I'm trying to figure out why it works on the DTL testing tool, but doesn't while running in the actual Process.
Commonly Used Stream Methods and Properties
"Write() — Append data to the stream, starting at the current position. Overwrites existing data if the position is not set to the end of the stream."
The solution wound up being to create a new %Stream.GlobalCharacter Stream, read from the source object stream and write the replaced string to this stream, and finally set it to the Ens.StreamContainer target object.
I still have no idea why creating a new stream works while re-writing the existing stream doesn't. The docs seem to imply it should work and even saving the stream after writing didn't do anything different. In Message Viewer, I can see its creating a new body object, as well. Creating a new Stream object works, so I guess that's fine.