A
Andreas Huber
Hi
I have a stream containing data with potentially many different encodings.
It seems this precludes the direct use of the StreamReader class, for the
following reasons:
1) The encoding is fixed at StreamReader construction time
2) When I'm done reading data in encoding X and would want to continue in
encoding Y, I cannot simply trash my current StreamReader and continue with
a new one. This is because the old one very likely has yet undecoded bytes
left in its internal buffer. Those bytes have already been read from the
stream but were not decoded because we've come to the conclusion that we
need to continue with a different encoding. The bytes in the old
StreamReader buffer would therefore be lost.
3) Constructing a StreamReader with
new StreamReader(myStream, myEncoding, false, 1) // note the request for a
buffer size of 1 byte
doesn't help as the constructor internally enforces a minimal buffer size of
128 bytes.
Just wanted to check if someone else has a better idea before I go and
either implement my own StreamReader (duplicating much of the stock .NET
StreamReader) or chop up the underlying stream at the byte level (e.g. by
using one byte buffer for each area with a given encoding).
Thanks,
I have a stream containing data with potentially many different encodings.
It seems this precludes the direct use of the StreamReader class, for the
following reasons:
1) The encoding is fixed at StreamReader construction time
2) When I'm done reading data in encoding X and would want to continue in
encoding Y, I cannot simply trash my current StreamReader and continue with
a new one. This is because the old one very likely has yet undecoded bytes
left in its internal buffer. Those bytes have already been read from the
stream but were not decoded because we've come to the conclusion that we
need to continue with a different encoding. The bytes in the old
StreamReader buffer would therefore be lost.
3) Constructing a StreamReader with
new StreamReader(myStream, myEncoding, false, 1) // note the request for a
buffer size of 1 byte
doesn't help as the constructor internally enforces a minimal buffer size of
128 bytes.
Just wanted to check if someone else has a better idea before I go and
either implement my own StreamReader (duplicating much of the stock .NET
StreamReader) or chop up the underlying stream at the byte level (e.g. by
using one byte buffer for each area with a given encoding).
Thanks,