converting character stream into binary stream and vice versa

412 views
Skip to first unread message

Dom

unread,
Jul 23, 2014, 6:13:46 AM7/23/14
to intersystems...@googlegroups.com
Hi,

is there a simple way to convert a Binary stream (either global or file) into a Character Stream (either global or file)

Been looking through the stream methods but couldn't see anything.

Thanks
Dom

sitc...@gmail.com

unread,
Jul 31, 2014, 10:04:24 AM7/31/14
to intersystems...@googlegroups.com
If you are storing character data than there is nothing to do, note that GlobalCharacter is a super class of GlobalBinary.

Set Text(1) = "This is line one of some text."
Set Text(2) = "This is line two of some text."
Set Text(3) = "This is line three of some text."

Set stream = ##class(%Stream.GlobalBinary).%New()
For i=1:1:3 Do stream.WriteLine(Text(i))

Do stream.Rewind()
While ('stream.AtEnd) Write !,stream.ReadLine() }

Do stream.Rewind()
Set chars = ##class(%Stream.GlobalCharacter).%New()
Do chars.CopyFrom(stream)

Do chars.Rewind()
While ('chars.AtEnd) Write !,chars.ReadLine() }

Output:
This is line one of some text.
This is line two of some text.
This is line three of some text.
This is line one of some text.
This is line two of some text.
This is line three of some text.
Reply all
Reply to author
Forward
0 new messages