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

Stream.Read to Bytearray Problem

When I want to Read the Bytes 1000-2000 from a Stream into a ByteArray using

Stream.Read(byteArray,1000,2000)

they are written to the positions 1000-2000 in the byteArray.

but my Array is only 1000 items long Array(0-999), and i just want to have
the positions 1000-2000 from the stream!

How can i realize it that the bytes 1000-2000 are written to an Array of
length=1000

PS: The Stream is reading from the Internet

Thanx in advice
Nov 18 '05 #1
1 990
Daniel von Fersen wrote:
When I want to Read the Bytes 1000-2000 from a Stream into a
ByteArray using

Stream.Read(byteArray,1000,2000)

they are written to the positions 1000-2000 in the byteArray.
but my Array is only 1000 items long Array(0-999), and i just want to
have the positions 1000-2000 from the stream!

How can i realize it that the bytes 1000-2000 are written to an Array
of length=1000


Trick answer: Never... counting from 1000 to 2000 gives you 1001 bytes ;-)

You misinterpreted the meaning of the parameters passed to Stream.Read().
The third parameter is not an end index (that would be a rather strange
notion regarding streams), but the numbers of bytes you want to read at
most. Thus, if you want to consume 1000 bytes starting at index 1000, use

someStream.Read(buffer, 1000, 1000);
BTW, there is a framework group that is more appropriate for these kinds of
questions.

Cheers,

--
Joerg Jooss
jo*********@gmx.net

Nov 18 '05 #2

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

Similar topics

11
by: Detlef Hüttenbach | last post by:
Whereas loading tiffs and pngs from file into an Image WebControl work, the images aren't shown when loaded from streams: In a WebForm, the image's property "ImageUrl" is set to a handler, and...
1
by: Daniel von Fersen | last post by:
When I want to Read the Bytes 1000-2000 from a Stream into a ByteArray using Stream.Read(byteArray,1000,2000) they are written to the positions 1000-2000 in the byteArray. but my Array is...
4
by: Daniel von Fersen | last post by:
Hallo, Wenn ich mit Stream.Read(buffer,1000,2000) 1000 bytes in ein Bytearray einlesen möchte werden diese Bytes an die positionen 1000-2000 geschrieben! Ich möchte jedoch (da ich nur diesen...
8
by: Daniel von Fersen | last post by:
When I want to Read the Bytes 1000-2000 from a Stream into a ByteArray using Stream.Read(byteArray,1000,2000) they are written to the positions 1000-2000 in the byteArray. but my Array is...
2
by: bill tie | last post by:
How do I convert ADODB.Stream into an array of bytes? Thank you.
5
by: Simon Rigby | last post by:
Hi folks, Apologies if this is not directly relevant but I was struggling to find a group with the appropriate context. So as my problem is in an aspx web site I thought I'd try here first....
1
by: pax82 | last post by:
hi, sorry for my english but i don't speak good english. in this web service i send 2 data stream(xml and xsl file) and i would like to return a xslt trasform-file byte array (now i return string...
11
by: Icemokka | last post by:
Hi, I'm need to upload a big file ( 600Mb+ ) to a BLOB field in MSSQL 2005. My code looks like this : fs = New FileStream(sFilePath, FileMode.Open) Dim ByteArray(fs.Length) As Byte...
0
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
5
by: Nitin Mahajan | last post by:
Guys Is there a way in C# to create a word object directly from a memory stream without passing that to hard disk (file stream). I think it doesn't makes sense to create a file just to read it...
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
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.