473,387 Members | 1,516 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,387 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 1319
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

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: 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
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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.