Using streams with Russian language

Primary tabs

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.

Answers

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

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)

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.