closing WriteStream?

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

closing WriteStream?

Tim Johnson
Hi,

Do I need to worry about closing a WriteStream?  Currently I am working
like this:

buildStatementFor: anObject
| statement |
statement := String new writeStream.
[
statement nextPutAll: 'bla bla bla'.
^ statement contents.
] ensure: statement close



... is that not needed?

Thanks,
Tim


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: closing WriteStream?

Jerome Peace
[Newbies] closing WriteStream?

***

>Mr. Timothy C. Johnson tjohnson at iwu.edu
>Wed Nov 26 01:10:46 UTC 2008
>
>
>Hi,
>
>Do I need to worry about closing a WriteStream?  Currently I am working
>like this:
>
>buildStatementFor: anObject
>| statement |
>statement := String new writeStream.
>[
>statement nextPutAll: 'bla bla bla'.
>^ statement contents.
>] ensure: statement close
>
>
>
>... is that not needed?
***

Look at #streamContents: (and its 300+ senders) for
 a really popular way of doing what you want.

Yours in curiosity and service, --Jerome Peace



     
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: closing WriteStream?

Bert Freudenberg
In reply to this post by Tim Johnson

On 26.11.2008, at 02:10, Mr. Timothy C. Johnson wrote:

> Hi,
>
> Do I need to worry about closing a WriteStream?  Currently I am  
> working
> like this:
>
> buildStatementFor: anObject
> | statement |
> statement := String new writeStream.
> [
> statement nextPutAll: 'bla bla bla'.
> ^ statement contents.
> ] ensure: statement close
>
>
>
> ... is that not needed?

Not for an in-memory write stream no.

Note you're missing the block brackets around [statement close].

Also, since this is such a common task, the shorter version is

buildStatementFor: anObject

        ^String streamContents: [:statement | statement nextPutAll: 'bla bla  
bla']

Take a look at #streamContents: which does exactly the same as your  
code, but you can never get it wrong again ;)

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: closing WriteStream?

Tim Johnson
In reply to this post by Tim Johnson
Bert Freudenberg wrote:

>> Do I need to worry about closing a WriteStream?  Currently I am  
>> working
>> like this:
>>
>> buildStatementFor: anObject
>> | statement |
>> statement := String new writeStream.
>> [
>> statement nextPutAll: 'bla bla bla'.
>> ^ statement contents.
>> ] ensure: statement close
>>
>
>Not for an in-memory write stream no.
>
>Note you're missing the block brackets around [statement close].
>
>Also, since this is such a common task, the shorter version is
>
>buildStatementFor: anObject
>
> ^String streamContents: [:statement | statement nextPutAll: 'bla bla  
>bla']
>
>Take a look at #streamContents: which does exactly the same as your  
>code, but you can never get it wrong again ;)

Hi Bert,

Thanks.  Actually that was (of course!) just an off-the-cuff pseudocode
I posted and not a copy-and-paste.  My email client does not have a
syntax checker, unfortunately :)

#streamContents: indeed seems to be what I need.

- TimJ


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners