473,789 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reuse io.stream object

Hi there,

I have the following:

Dim objResponse As WebResponse = objReq.GetRespo nse
Dim objStream As IO.Stream

objStream = objResponse.Get ResponseStream

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 1668
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.GetRespo nse
Dim objStream As IO.Stream

objStream = objResponse.Get ResponseStream

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******** ******@TK2MSFTN GP09.phx.gbl...
Hi there,

I have the following:

Dim objResponse As WebResponse = objReq.GetRespo nse
Dim objStream As IO.Stream

objStream = objResponse.Get ResponseStream

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
7465
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
2386
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 in the Sky,' Vernor Vinge described a future where software is created by 'programmer archaeologists' who search archives for existing pieces of code, contextualize them, and combine them into new applications. So
3
4890
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 responses as quickly as possible, then do it again. For my last attempt, I tried implementing a circular queue of precreated HttpWebRequest objects, then creating a HttpWebResponse, StreamReader, and Stream and disposing of them after usage. My...
7
1446
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 (ev.locationList != null) { //isListNull = true ensures that we do not recheck the list every time we add a new item bool isListNull = false;
0
9663
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
9511
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
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
10195
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...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9016
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
7525
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
6765
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();...
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.