Streams, nextPut: and illegal characters

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

Streams, nextPut: and illegal characters

Holger Kleinsorgen-4
Hi,

various stream classes implement #nextPut: in a way that makes it
impossible to catch illegal characters. Consider writing arbitrary
characters to a file stream with an arbitrary encoding. This may raise
an UnsupportedCharacterError for characters not suitable for the
encoding. There's currently no way to skip the bad character and resume
with the next character, due to the way #nextPut: is implemented, e.g.
in class ExternalWriteStream


ExternalWriteStream nextPut:

        .....
        collection at: (position := position + 1) put: aByte.
        .....

#at:put: may raise an error that can be resumed, but due to the
preincrement of the inst var position, the output stream will then
contain a gap, usually filled with a zero.

I would be happy if this could be improved in VW by incrementing
position after #at:put:.

Regards, Holger

Reply | Threaded
Open this post in threaded view
|

Re: Streams, nextPut: and illegal characters

Alan Knight-2
You might find it useful to use the stream extensions in Wave-Server-Base. These give an error policy object to StreamEncoder which allow it to control what processing is used. This is used in VisualWave and WebToolkit to handle characters outside of the encoding in use when writing to a web page by encoding them with the &1234; encoding, but could allow arbitrary other usage. Unfortunately, that only affects EncodedStreams, not basic ExternalWriteStream. And it's in with a bunch of other unrelated Wave changes to the base.

There is already an AR pending (47827) to integrate this capability into the base image, and I'll take a look at it to see if it can be extended to non-encoded external streams as well.

At 05:15 AM 1/25/2006, Holger Kleinsorgen wrote:

>Hi,
>
>various stream classes implement #nextPut: in a way that makes it impossible to catch illegal characters. Consider writing arbitrary characters to a file stream with an arbitrary encoding. This may raise an UnsupportedCharacterError for characters not suitable for the encoding. There's currently no way to skip the bad character and resume with the next character, due to the way #nextPut: is implemented, e.g. in class ExternalWriteStream
>
>
>ExternalWriteStream nextPut:
>
>        .....
>        collection at: (position := position + 1) put: aByte.
>        .....
>
>#at:put: may raise an error that can be resumed, but due to the preincrement of the inst var position, the output stream will then contain a gap, usually filled with a zero.
>
>I would be happy if this could be improved in VW by incrementing position after #at:put:.
>
>Regards, Holger

--
Alan Knight [|], Cincom Smalltalk Development
[hidden email]
[hidden email]
http://www.cincom.com/smalltalk

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." - Niall Ross