[Glass] UTF8 and FileStreams via GsFile ?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Tue Oct 3 04:57:29 PDT 2017

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.


On Tue, Oct 3, 2017 at 5:28 AM, Marten Feldtmann via Glass <
glass at lists.gemtalksystems.com> 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
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20171003/549eb552/attachment.html>

More information about the Glass mailing list