473,385 Members | 1,445 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,385 software developers and data experts.

Please explain DiscardBufferedData

Hi,

Can someone please explain to me what the
StreamReader.DiscardBufferedData method does?
The documentation says
"Use DiscardBufferedData to seek to a known location in the underlying
stream and then begin reading from this new point, or to read the
contents
of a StreamReader more than once."
I am not able to understand what exactly this means.

I am particularly looking for how this method manipulates the buffer.

In our VB .NET program, we spawn an FTP process to which we write
commands and read back the result. For this we use StandardInput and
StandardOutput property of the Process.

To send a command to the process, we do:
SendCommand:
Me.FTPProcess.StandardInput.WriteLine(cmd)
Me.FTPProcess.StandardOutput.DiscardBufferedData()

To read the result of the command we have:
ReadResult:
While Me.FTPProcess.StandardOutput.Peek() > -1
ftpResp = Me.FTPProcess.StandardOutput.ReadLine()
End While

When sending the command, if we do not use the DiscardBufferedData, we
noticed that the program does not read the result. The Peek function
returns -1. For some commands, the peek method also blocked
indefinitely.
If the DiscardBufferedData is kept, output from previous commands is
read followed by output of the recent command. This is probably what
is meant by the above line from the documentation.

We want to ensure that after every command, only the output of that
command is read.

Any ideas or suggestions?

Thanks
Jul 21 '05 #1
1 4468
Yash <ya****@yahoo.com> wrote:
Can someone please explain to me what the
StreamReader.DiscardBufferedData method does?
Sure. When you ask a StreamReader to read some data, it reads more than
you ask for, for performance reasons. Next time you ask it to read, if
it can satisfy the request without reading anything else from the
underlying stream, it will do so. That causes problems if you're
repositioning the underlying stream, or something like that.
In our VB .NET program, we spawn an FTP process to which we write
commands and read back the result. For this we use StandardInput and
StandardOutput property of the Process.

To send a command to the process, we do:
SendCommand:
Me.FTPProcess.StandardInput.WriteLine(cmd)
Me.FTPProcess.StandardOutput.DiscardBufferedData()
I see no reason to call DiscardBufferedData there.
To read the result of the command we have:
ReadResult:
While Me.FTPProcess.StandardOutput.Peek() > -1
ftpResp = Me.FTPProcess.StandardOutput.ReadLine()
End While

When sending the command, if we do not use the DiscardBufferedData, we
noticed that the program does not read the result. The Peek function
returns -1. For some commands, the peek method also blocked
indefinitely.
If the DiscardBufferedData is kept, output from previous commands is
read followed by output of the recent command. This is probably what
is meant by the above line from the documentation.

We want to ensure that after every command, only the output of that
command is read.

Any ideas or suggestions?


I think your manner of reading results is basically somewhat flawed. It
will think that a command's result has completed even if it's really
just pausing, for instance.

Instead, you should try to work out what the process will return as the
final line when it's finished, and loop until you see that (or the
stream is closed).

Having said all that, it would probably be easier to use an FTP library
instead of spawning a process in the first place.

See http://www.indyproject.org for one such library.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

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

Similar topics

9
by: DD | last post by:
Hello, Could anyone please help me?? Is there somebody who could explain me how to make a connection to a access database with a python cgi script. I would like to use common sql commands in my...
3
by: VijayShankar | last post by:
Can u be more specific on your question Anyway its not like Session variables are available for sometime and not available for sometime. When your session starts it is very much available...
12
by: Sanjeev | last post by:
Output of followin program at Turbo C++ 3.0 is 7 ( Not 2 or 3). Please explain why ? //////////////////////////////////////////////// #include<stdio.h> #include<string.h> void main() {
1
by: Yash | last post by:
Hi, Can someone please explain to me what the StreamReader.DiscardBufferedData method does? The documentation says "Use DiscardBufferedData to seek to a known location in the underlying stream...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
9
by: colin.mcnulty | last post by:
Hi, I'm a SQL Server DBA, but I guess that won't buy me any friends round here huh? ;-) I've been asked to look at the SQL that's being executed on a DB2 database from a web app, specifically...
61
by: warint | last post by:
My lecturer gave us an assignment. He has a very "mature" way of teaching in that he doesn't care whether people show up, whether they do the assignments, or whether they copy other people's work....
3
by: sathishc58 | last post by:
Hi All, Here is the code which generates Segmentation Fault. Can anyone explain why the third printf fails and the first printf works? main() { char ch={"Hello"}; char *p; ...
2
by: sathishc58 | last post by:
Hi All Please explain why strlen returns() "16" as output here and explain the o/p for sizeof() as well main() { char a={'a','b','c'}; printf("strlen=%d\n", strlen(a));...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.