Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. EndOfStream in BinaryReader

EndOfStream in BinaryReader

Scheduled Pinned Locked Moved Visual Basic
questioncomhelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yuvi Panda
    wrote on last edited by
    #1

    What is the way to check for EndOfStream while using a Binary Reader ? StreamReader has the EndOfStream Property, but there seems to be no equivalent Property in BinaryReader. I am using BinaryReader because I am dealing with Byte Arrays, and sadly, StreamReader seems to insit on reading Character Arrays. And, the Stream I am reading doesn't support Seeking, so we cannot check if the Position Property is equal to the Length... I googled for it, but can't seem to find anything. Any help people ? Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

    D 1 Reply Last reply
    0
    • Y Yuvi Panda

      What is the way to check for EndOfStream while using a Binary Reader ? StreamReader has the EndOfStream Property, but there seems to be no equivalent Property in BinaryReader. I am using BinaryReader because I am dealing with Byte Arrays, and sadly, StreamReader seems to insit on reading Character Arrays. And, the Stream I am reading doesn't support Seeking, so we cannot check if the Position Property is equal to the Length... I googled for it, but can't seem to find anything. Any help people ? Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Yuvi Panda wrote:

      and sadly, StreamReader seems to insit on reading Character Arrays

      That's what it was designed to do! From the MSDN docs on StreamReader:

      StreamReader Class
       
      Implements a TextReader that reads characters from a byte stream in a particular encoding.

      As for the BinaryReader[^], you're looking for it's [PeekChar](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx)[[^](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx "New Window")] method. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 8:57 Friday 21st April, 2006

      Y 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Yuvi Panda wrote:

        and sadly, StreamReader seems to insit on reading Character Arrays

        That's what it was designed to do! From the MSDN docs on StreamReader:

        StreamReader Class
         
        Implements a TextReader that reads characters from a byte stream in a particular encoding.

        As for the BinaryReader[^], you're looking for it's [PeekChar](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx)[[^](http://msdn2.microsoft.com/en-us/library/system.io.binaryreader.peekchar.aspx "New Window")] method. Dave Kreskowiak Microsoft MVP - Visual Basic -- modified at 8:57 Friday 21st April, 2006

        Y Offline
        Y Offline
        Yuvi Panda
        wrote on last edited by
        #3

        Thanks, but I am reading from a Network Stream, which Does Not support Peeking. Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com -- modified at 22:44 Friday 21st April, 2006

        M 1 Reply Last reply
        0
        • Y Yuvi Panda

          Thanks, but I am reading from a Network Stream, which Does Not support Peeking. Yuvi Panda T Microsoft Student Partner Blogs at : http://yuvipanda.blogspot.com -- modified at 22:44 Friday 21st April, 2006

          M Offline
          M Offline
          mafaz321
          wrote on last edited by
          #4

          Hello there, I found a wayout to check for the end of stream. using (BinaryReader br = new BinaryReader(fs)) { while(fs.Position<fs.Length) { //add your code till it finds the end of the BinaryFile line. } } ...assuming that "fs" is defined as the FileStream in the outer block. Hope this works... Mafaz

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups