UTF8 and FileStreams via GsFile ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UTF8 and FileStreams via GsFile ?

GLASS mailing list

Hey,

here is a simple question - how do I read and write a UTF8 (or with different encoding) file in Gemstone/S. What are the protocols ? I just do conversion manually everywhere and this is clearly not the way to go ...


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass
Reply | Threaded
Open this post in threaded view
|

Re: UTF8 and FileStreams via GsFile ?

GLASS mailing list
First, check GRUtf8CodecStream (this is what I use.... even outside seaside). There, you can see for example how the method  #nextPutAll:  calls the #_encodeAsUTF8intoString

Another possibility is to do something like this:

 | file |
  file := GsFile open: aFilename mode: 'w' onClient: false.
  file nextPutAll: aString encodeAsUTF8.
  file close

Finally, Gemstone 3.4 comes with new primitives and some helper methods to better deal with streaming and UTF8. The classes in question are StringAppendStream and AppendStream. The new primitive is #addAllUtf8:.   So you can replace previous writing like this:

    aStream nextPutAll:  aString encodeAsUTF8

with this:

   anAppendStream nextPutAllUtf8: aString

AppendStream is usually "safer" to use as its subclass from Stream. StringAppendStream might be slightly faster, but as it subclass from String, it has a few Stream like methods. So you must be sure what you use from the stream API. 


Let me know if it helped.

Cheers,




On Tue, Oct 3, 2017 at 5:28 AM, Marten Feldtmann via Glass <[hidden email]> wrote:

Hey,

here is a simple question - how do I read and write a UTF8 (or with different encoding) file in Gemstone/S. What are the protocols ? I just do conversion manually everywhere and this is clearly not the way to go ...


_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass




--

_______________________________________________
Glass mailing list
[hidden email]
http://lists.gemtalksystems.com/mailman/listinfo/glass