473,408 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Reading & Writing in a Stream

Ali
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.
Nov 15 '05 #1
16 9071
Ali wrote:
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.

Nov 15 '05 #2
Cor
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 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?

Nov 15 '05 #3
I.hate,spam <"I.hate,spam" <"I.hate,spam"@my.email>> wrote:
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 Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Cor <no*@non.com> wrote:
Are you talking about a stream to disk, than you can just do it as strings.
(unicode is standard)


No, streams deal solely with binary data. To convert between text data
and binary data, you need to use an encoding.

See http://www.pobox.com/~skeet/csharp/unicode.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Cor
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

Nov 15 '05 #6
Cor <no*@non.com> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
Cor
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
Nov 15 '05 #8
Cor <no*@non.com> wrote:
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.


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*.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
Cor
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
Nov 15 '05 #10
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
Nov 15 '05 #11
Cor <no*@non.com> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #12
Cor
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
Nov 15 '05 #13
Cor <no*@non.com> wrote:
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.


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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #14
Cor
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
Nov 15 '05 #15
Cor <no*@non.com> wrote:
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?


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 Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #16
Cor
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.
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.


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

Cor
Nov 15 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
1
by: andrewcw | last post by:
OK I am half way there - I can manipulate the stream without the byte issue like this - but is this the way to push the new values back into the stream & write out the stream without resorting to...
3
by: Nick | last post by:
I have found a class that compresses and uncompresses data but need some help with how to use part of it below is the deflate method which compresses the string that I pass in, this works OK. At...
6
by: Neil Patel | last post by:
I have a log file that puts the most recent record at the bottom of the file. Each line is delimited by a \r\n Does anyone know how to seek to the end of the file and start reading backwards?
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
1
by: KWSW | last post by:
Got a question about reading and writing binary files. I know that to write a value(integer) to a binary file I can use the fileoutputstream to do it. try { // Create an output...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
1
by: Sebarry | last post by:
Hi, I'm trying to read the results of a database query into an XML document but it's only read so far and stopping. The XML document is as follows: <?xml version="1.0" encoding="utf-8"?> ...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.