Re: using FileStream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Tony Johansson <johansson.andersson@xxxxxxxxx> wrote:
Here I have an small piece of code from a program.

I have read about the last parameter of GetBytes but I can't really
understand it's use.

I mean that the GC would take care of flushing the Encoder object e without
having to say that.

What does this have to do with a FileStream (your subject line)?

So somebody explain the reason for having this last parameter in the method
GetBytes ?

Encoder e = Encoding.UTF8.GetEncoder();
e.GetBytes(chardata, 0, chardata.length, byteDataArray, 0, true):

It's so that you can either reuse the encoder with a completely
different set of bytes, *or* you can reuse it with subsequent bytes.
This is important if the last set of bytes you passed ended half way
through a character. If you flush the encoder, it will start again from
scratch. If you don't, it will expect the second half of the character
to be at the start of the next block of data.

Most of the time you don't need Encoder though - simply using Encoding
is good enough in most cases.

--
Jon Skeet - <skeet@xxxxxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
.



Relevant Pages

  • Re: using FileStream
    ... You might not get all the characters into the destination buffer. ... The documentation clearly says that the last call to the GetBytes method should have the parameter set to true to ensure that everything is flushed to the output. ... I mean that the GC would take care of flushing the Encoder object e ... it will expect the second half of the character ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: A plea: Looking for a working MM5740AAE/N for Apple II Keyboard
    ... to see if any kind soul has any AAE/N encoder chips left to spare. ... the most common keyboard problems. ... In other words, the character that comes out of the character generator is used as an address for the address pins of the eprom, and the data at that address will be the proper ascii character. ...
    (comp.sys.apple2)
  • Re: Graphedit for Windows Mobile
    ... video and AAC audio, I want to reuse those encoder, but I don't know whether ... Please do not multi-post. ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: codecs.getencoder encodes entire string ?
    ... For an encoder, I believe the answer is "no". ... the current UTF-8 encoder will then just encode the surrogate ... codepoint as if it was a proper character. ... If you extend the notion of "encoding", ...
    (comp.lang.python)
  • Re: How to generate java .properties files in python
    ... FTR, ... the 'backslashreplace' argument tells the encoder to replace any ... character that it can't encode with a backslash escape sequence. ...
    (comp.lang.python)