Reading & Writing in a Stream

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I want to write (or read) to a stream, but the data is not byte array
I converted the data to byte array manually, but it is very slow, (becuse the data is very large)
Is another way for this kind of writing and reading

best regard
Ali.
 
Ali said:
Hi,

I want to write (or read) to a stream, but the data is not byte array.
I converted the data to byte array manually, but it is very slow, (becuse the data is very large).
Is another way for this kind of writing and reading?

best regards
Ali.

Not all streams require byte arrays. Maybe try a StreamWriter for disk
output, or a StringWriter for writing to a string.
 
Hi Ali,

Are you talking about a stream to disk, than you can just do it as strings.
(unicode is standard)

I hope this helps,

Cor
 
I.hate said:
Not all streams require byte arrays. Maybe try a StreamWriter for disk
output, or a StringWriter for writing to a string.

Those aren't actually streams though - they're TextWriters, which are
sort of the *equivalent* of streams, but for text rather than binary
data.
 
Jon,
No, streams deal solely with binary data. To convert between text data
and binary data, you need to use an encoding.

This is maybe true, but the streamreader can be used to write direct data to
disk. You do not need to convert that first to a byte array. I explicitly
said "disk"

Cor
 
Cor said:
This is maybe true, but the streamreader can be used to write direct data to
disk.

Yes, but a StreamWriter isn't a Stream.
You do not need to convert that first to a byte array. I explicitly
said "disk"

Actually, the disk part here is irrelevant, as a StreamWriter can write
to any stream - a NetworkStream, MemoryStream, FileStream, whatever.
The important thing is that you don't write strings to a Stream though
- you write them to a TextWriter (such as StreamWriter) which might
well in turn write bytes to an underlying Stream.
 
Hi Jon,
Actually, the disk part here is irrelevant, as a StreamWriter can write
to any stream - a NetworkStream, MemoryStream, FileStream, whatever.
The important thing is that you don't write strings to a Stream though
- you write them to a TextWriter (such as StreamWriter) which might
well in turn write bytes to an underlying Stream.

Do you mind if I ask you to read this yourself again, without any comments
of me.

:-)

Cor
 
Cor said:
Do you mind if I ask you to read this yourself again, without any comments
of me.

Sure. Have done. No problem with it as far as I can see.

A StreamWriter is a TextWriter. TextWriters deal with text, not binary
data - and a StreamWriter converts the text it is given *into* binary
data, which the stream it's created with can write. A stream itself
*only* deals with binary, not text.

The OP wants to know how to write data to a *stream*, so he can't do it
as strings - not without a StreamWriter or manually calling
Encoding.GetBytes etc.

Which bit of my post did you actually disagree with? Why do you feel
it's relevant whether or not the OP is writing to a disk?

(I missed something from your previous post, btw - a Stream*Reader*
doesn't write *anything* - it only *reads*.)
 
Hi Jon,

A newsgroup keep the messages open this is what you tell that is the
question from the OP
The OP wants to know how to write data to a *stream*, so he can't do it
as strings - not without a StreamWriter or manually calling
Encoding.GetBytes etc.

This is the question from the OP (copied from his message)
I want to write (or read) to a stream, but the data is not byte array.
I converted the data to byte array manually, but it is very slow, (becuse
the data is very large).
Is another way for this kind of writing and reading?
---------------------------------------------------------
I do not know if he means to mem. to http or to disk. Therefore I gave the
answer that if it is to disk, it is not necessary to make first that
bytearray.

I did not tell how, that could be done when he had asked for that or maybe
he had answered that it was not to disk and than I had given another answer.

Cor
 
Hi Jon,

I forgot to thank you for this greath answer.
(I missed something from your previous post, btw - a Stream*Reader*
doesn't write *anything* - it only *reads*.)

I hope that I do not disappoint you, when I tell you that I did know that
already but made a typo.

:-)

Cor
 
Cor said:
A newsgroup keep the messages open this is what you tell that is the
question from the OP

This is the question from the OP (copied from his message)
I want to write (or read) to a stream, but the data is not byte array.
I converted the data to byte array manually, but it is very slow, (becuse
the data is very large).
Is another way for this kind of writing and reading?

Why though? How would you do things differently if it's writing to a
disk compared with writing anywhere else?
I did not tell how, that could be done when he had asked for that or maybe
he had answered that it was not to disk and than I had given another answer.

Well, you said you could write strings directly using a stream, which
you can't - you need to wrap it with a StreamWriter first, and that's
true whether the stream is to memory, the network or wherever.
 
Hi Jon,

Well, you said you could write strings directly using a stream, which
you can't - you need to wrap it with a StreamWriter first, and that's
true whether the stream is to memory, the network or wherever.

Show me where I wrote that above, this is the X th time you are telling from
people what they said, while they did not.

So copy it where I wrote that and show it.

But as usualy you answer this not anymore because you cannot.

Cor
 
Cor said:
Show me where I wrote that above, this is the X th time you are telling from
people what they said, while they did not.

So copy it where I wrote that and show it.

But as usualy you answer this not anymore because you cannot.

My mistake, you didn't use the word "directly". However, you did say:

<quote>
Are you talking about a stream to disk, than you can just do it as
strings.
</quote>

Which you can't. You can't (directly - my word) write a string to a
stream. You *have* to go through a conversion process (which is what
the OP apparently wanted to avoid) whether that's done directly using
Encoding or using StreamWriter. It doesn't matter whether you're
writing to a disk or not.

Your post gave the impression (to me at least) that you thought you
could write strings directly to a stream, which you can't.
 
Hi Jon,
Your post gave the impression (to me at least) that you thought you
could write strings directly to a stream, which you can't.

Did you see me write here that I thought that you said that it was only
possible to write bytearrays to disk?

That I could have been writing very easy by what you where telling and than
telling to you that you can only write bytes to a disk.

I expect that you know those basic things.


Cor
 
Cor said:
Did you see me write here that I thought that you said that it was only
possible to write bytearrays to disk?

No, I didn't - but that's basically true. Of course, you can *convert*
strings to byte arrays using StreamWriter, but it's still going to
write bytes to disk, one way or other.
That I could have been writing very easy by what you where telling and than
telling to you that you can only write bytes to a disk.

Sorry, could you rephrase that? I didn't understand that sentence.

I still say it's irrelevant whether or not the OP's stream is writing
to disk though.
 
Jon,
No, I didn't - but that's basically true. Of course, you can *convert*
strings to byte arrays using StreamWriter, but it's still going to
write bytes to disk, one way or other.


Sorry, could you rephrase that? I didn't understand that sentence.

Not needed see the phrase of you before that, the meaning is almost exactly
the same.

Cor
 
Back
Top