473,385 Members | 1,582 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.

Reuse io.stream object

Hi there,

I have the following:

Dim objResponse As WebResponse = objReq.GetResponse
Dim objStream As IO.Stream

objStream = objResponse.GetResponseStream

Then, I read some Bytes from this stream and it works. I then go do some
other things, still withing the scope of objStream,
then come back to "objStream" and would like to start over reading all of
the Bytes in objStream. It won't let me reset the position=0 on
the objStream. How can I reset or reuse objStream without going through my
WebRequest/WebResponse again?

Thanks,
Marc.
Nov 21 '05 #1
3 1630
In article <O6**************@TK2MSFTNGP09.phx.gbl>, "Marc Thompson" <(NO
SPAM) my email address is marc at sycron dot com> says...
Hi there,

I have the following:

Dim objResponse As WebResponse = objReq.GetResponse
Dim objStream As IO.Stream

objStream = objResponse.GetResponseStream

Then, I read some Bytes from this stream and it works. I then go do some
other things, still withing the scope of objStream,
then come back to "objStream" and would like to start over reading all of
the Bytes in objStream. It won't let me reset the position=0 on
the objStream. How can I reset or reuse objStream without going through my
WebRequest/WebResponse again?


One idea would be to read the entire stream into a byte array and then
create a MemoryStream from the byte array. Depending on the size of
your stream this may not be an option, but it would give you a stream
that you can reset to position zero.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 21 '05 #2
Marc,

Why you want to reuse it and not just close it and create a new one.

I ask this because some people think it is better to reuse. When we think
about the immutable strings than you know than that is in my opinion a
little bit from the past. You can just create a new object and the memory of
the old one will be reused. However probably all on another place.

Better is in my opinion to close it as soon as possible.

Just my thought,

Cor
Nov 21 '05 #3
Thanks for the replies fellas,

I decided to save the original stream to disk (part of the requirements
anyways). I then read the stream in from disk and finish my other
operations.

Probably would be more efficient to make a duplicate of the stream in memory
but oh well.

Why won't MS give us a stream copy/clone function? It's not that many lines
of code!!!!

Thanks again,
Marc.
"Marc Thompson" <(NO SPAM) my email address is marc at sycron dot com> wrote
in message news:O6**************@TK2MSFTNGP09.phx.gbl...
Hi there,

I have the following:

Dim objResponse As WebResponse = objReq.GetResponse
Dim objStream As IO.Stream

objStream = objResponse.GetResponseStream

Then, I read some Bytes from this stream and it works. I then go do some
other things, still withing the scope of objStream,
then come back to "objStream" and would like to start over reading all of
the Bytes in objStream. It won't let me reset the position=0 on
the objStream. How can I reset or reuse objStream without going through
my WebRequest/WebResponse again?

Thanks,
Marc.

Nov 21 '05 #4

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

Similar topics

9
by: Charles Prince | last post by:
How do I reuse a ostrstream? So far I have replaced all code that does this "delete <ostrstream>.str()" with "<ostrstream>.freeze(0)"
19
by: jacob navia | last post by:
There is an interesting discussion running in Slashdot now, about code reuse. The thema of the discussion is here: < quote > Susan Elliot Sim asks: "In the science fiction novel, 'A Deepness...
3
by: matadon | last post by:
Hi, I am writing a C# app. I have a finite (~50) set of URLs that I am continuously polling in a circular manner. I would like to do this in a way that can send out each of the requests and get...
7
by: RichB | last post by:
I am just trying to get to grips with C# and OOP, and one of the benefits would seem to be code reuse. However I am not sure where to draw the line. I have the following section of code: if...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.