By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,475 Members | 954 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,475 IT Pros & Developers. It's quick & easy.

Stream Reader blues.

P: n/a


Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Unless their is something I am missing you can check to see if the byte
array that was returned is less than the requested length.

Public Overridable Function ReadBytes( ByVal count As Integer) As Byte()

"jamie" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

Nov 20 '05 #2

P: n/a
* "jamie" <an*******@discussions.microsoft.com> scripsit:
Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"


<URL:http://www.yoda.arachsys.com/csharp/readbinary.html>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #3

P: n/a
Jamie,
As spamtrap suggested, you can check the size of the array returned.

If any method of BinaryReader threw an exception while I was using it, I
would not care if the position was advanced or not, as I would consider the
entire BinaryReader to be invalid and get ride of it!

Hope this helps
Jay

"jamie" <an*******@discussions.microsoft.com> wrote in message
news:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables
from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:

A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if
it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?

Thanks for all the help you ppls can give me. Unfortunatly
the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

Nov 20 '05 #4

P: n/a
oh yea, the array is dimensioned in the method, so I could
use array.length . I could work with that.

thanks

-----Original Message-----
Unless their is something I am missing you can check to see if the bytearray that was returned is less than the requested length.

Public Overridable Function ReadBytes( ByVal count As Integer) As Byte()
"jamie" <an*******@discussions.microsoft.com> wrote in messagenews:0b****************************@phx.gbl...


Im trying to use a binaryreader to read in afew variables from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"

But.... their explanation for the function is as follows:
A byte array containing data read from the underlying
stream. THIS MIGHT BE LESS THAT THE NUMBER OF BYTES
REQUESTED IF THE END OF THE STREAM IS REACHED.

How can I tell if I got all the bytes that I wanted, or if it came up short?????? If it does throw an error, is the
stream pointer still advanced?

What would happen if I used readDouble and it didnt have
all the data required to create the double? Does the
stream pointer still advance? and is an exception thrown?
Thanks for all the help you ppls can give me. Unfortunatly the nine or ten books and the vb help dont give all the
answers I need.(atleast not in english)

.

Nov 20 '05 #5

P: n/a
PERFECT!!!! thats what I needed!!!
-----Original Message-----
* "jamie" <an*******@discussions.microsoft.com> scripsit:
Im trying to use a binaryreader to read in afew variables from tcpip. The method I was trying to use was:
"ReadBytes(byval count as integer) as bytes"


<URL:http://www.yoda.arachsys.com/csharp/readbinary.html>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
<URL:http://dotnet.mvps.org/dotnet/faqs/>
.

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.