Rustam Ibragimov · Aug 5, 2016

Using streams with Russian language

Hello, guys.

I need to copy the text from one stream to another filestream and save it. I am using  

do fileStream.CopyFromAndSave(rtn.Code)

However, if "rtn" stream contains Russian characters I get something like "???". Is there any way to convert stream to Unicode?  Something like $zc(str, "O", "UTF8") for streams.

0 335
Discussion (3)1
Log in or sign up to continue

As you have not showed full example of your code, I suggest that you use wrong class for fileStream.

For any text's you should use Character's stream, such as %Stream.FileCharacter, %Stream.GlobalCharacter

For file character streams you need to specify TranslateTable property, which is internal translation table based on your locale. 

For translation to utf-8 you need to set:

 set  fileStream   ##class( %FileCharacterStream). %New()
 set  fileStream .Filename  fileLocation

 set fileStream .TranslateTable ="UTF8"

 set status  fileStream .CopyFromAndSave (rtn .Code )

It should help.

fileStream is of type %FileCharacterStream and rtn.Code is of type %CharacterStream

This is the code: 

set rtn = ##class(%RoutineMgr).%OpenId(fileName)
  // write content to file
set fileStream = ##class(%FileCharacterStream).%New()
set fileStream.Filename = fileLocation

set status = fileStream.CopyFromAndSave(rtn.Code)