Re: how to dispose of a streamwriter without closing the underlying stream



On Wed, 10 Dec 2008 01:48:10 -0800, <ajfish@xxxxxxxxxxxxxxxx> wrote:

Thanks for all the responses. I think peter's solution is a good way
to go. I'm just curious as to why MS couldn't have put some kind of
property on the StreamWriter to affect whether it closes the
underlying stream.

You'd have to ask Microsoft. But, as you can see from these related discussions, what and how exactly to do that is not without complications. The reader/writer classes are dependent on encoding and exact byte position, and there's no way to ensure that a reader in particular hasn't read some bytes that are actually part of a different encoding (for streams that mix encodings or even non-text data).

I would guess that since there's not really any reliable way to generalize that kind of functionality, the framework leaves it up to the application to do it, under its full control so that any mistakes in dealing with the mixed data stream are the fault of the application, not the framework. :)

Pete
.



Relevant Pages

  • Re: Send string to IP address
    ... "Plain hex" implies something formatted as text, but doesn't answer the question of encoding. ... There's no "just" as far as "an ASCII string" is concerned. ... Characters are not bytes and bytes are not characters. ... Normally you'd create the Writer once at the same time as you create the underlying stream, rather than every time you write some text, obviously. ...
    (comp.lang.java.programmer)
  • Re: combine serveral .txt files
    ... Open the first stream to read from ... When you've finished all the files, close the output stream. ... the files are using the same encoding. ... and the bicycle has to *want* to change. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Character semantics for filenames (was: win32 reading wide filenames (unicode))
    ... DO WITH CHARACTERS ABOVE "\xFF". ... suspect, openworks on the supplied byte stream AS IS, discregarding ... Unocode inserts hints in strings. ... encoding to perl strings by readdir and from perl strings to the OS ...
    (comp.lang.perl.misc)
  • Re: Stream and Encoding Confusion
    ... We are each writing programs to read an input file and count the number of ... a simple list that says we the program found so many of each character; ... treated as a character stream or a byte stream. ... I'm also somewhat concerned about encoding. ...
    (comp.lang.java.programmer)
  • RE: Object serialization and NetworkStream - extraneous characters in output
    ... when you retrieve the stream and try reading the ... you found there is an additional header "o;?" ... As for the problem you mentioned, I think it is likely due to the encoding ... ASCII stream won't have such a header). ...
    (microsoft.public.dotnet.framework)