473,785 Members | 2,801 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9112
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.co m>
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.co m>
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.co m>
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.GetByt es 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.co m>
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.GetByt es 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

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

Similar topics

4
9843
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 = tmpfile(); /* write into tmpFile */ ...
1
26804
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 byte conversion ?? FileStream stream = null; stream = File.Open(fiPath, FileMode.Open, FileAccess.ReadWrite,FileShare.None); System.IO.StreamReader Tin = new System.IO.StreamReader (stream);
3
9512
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 the end of this message is the inflate method this is where I get stuck I know that I need a byte array but because I am decompressing a string I have no idea of how big the byte array will need to be in the end (the inflate and deflate methods...
6
44119
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
13101
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 server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in quotations. So, I'm able to open a connection to the server. When I send a message to
1
2910
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 stream to the file. FileOutputStream file_output = new FileOutputStream (outFile); //for(int i = 0; i < cInt.length; i++)
0
4729
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 -Guarantees that no data loss will occur if the primary database fails. To provide this level of protection, the redo data needed to recover each transaction must be written to both the local online redo log and to a standby redo log on at least...
1
2131
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"?> <night> <name>Poontang</name>
21
3066
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 00000000_00 0 000 000 000 0000 000 I need to read the file line by line and eventually parse out each piece of the file and store in arrays that correspond to the specific
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10336
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8978
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7502
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.