BinaryReader munges data  
Author Message
mikemps





PostPosted: Tue May 17 23:59:24 CDT 2005 Top

Visual C#.Net >> BinaryReader munges data I'm about to rip out what little hair I have left; I have a class that
uses a BinaryReader, and the data is getting munged. A subset of the
code follows; I've removed the parts that aren't relevant.

What's really strange is that it reads the file just fine until the
272nd call to the Read method of the class, at which point it begins
munging the data.

Any thoughts would be greatly appreciated; I've tried reading by byte,
as well as reading blocks, and it makes no difference.

-Kevin

public class HeaderStream
{
private const int c_BlockSize = 680;

private System.IO.BinaryReader str;

public HeaderStream(string path)
{
FileStream s = new FileStream(path,
FileMode.Open,
Read);

str = new BinaryReader(s);
}

public OWHeader Read()
{
byte[] buf = new byte[c_BlockSize];
int i;

i = str.Read(buf, 0, c_BlockSize);
if (i != c_BlockSize)
throw new EndOfStreamException(
String.Format(
"End of stream reached with bytes left to read"));

return new OWHeader(buf);
}
}

DotNet392  
 
 
Daniel





PostPosted: Tue May 17 23:59:24 CDT 2005 Top

Visual C#.Net >> BinaryReader munges data
"Kevin Trojanowski" <EMail@HideDomain.com> wrote in message
news:93yie.41606$gc6.33252@okepread04...
> I'm about to rip out what little hair I have left; I have a class that
> uses a BinaryReader, and the data is getting munged. A subset of the code
> follows; I've removed the parts that aren't relevant.
>
> What's really strange is that it reads the file just fine until the 272nd
> call to the Read method of the class, at which point it begins munging the
> data.
>
> Any thoughts would be greatly appreciated; I've tried reading by byte, as
> well as reading blocks, and it makes no difference.

How is it munging it? And could you show us a short but complete program[1]
that exhibits your problem? The code below just doesn't show whats going to
happen.

1. http://www.yoda.arachsys.com/csharp/complete.html



 
 
Kevin





PostPosted: Wed May 18 17:52:34 CDT 2005 Top

Visual C#.Net >> BinaryReader munges data Daniel O'Connell [C# MVP] wrote:

> How is it munging it? And could you show us a short but complete program[1]
> that exhibits your problem? The code below just doesn't show whats going to
> happen.

Nevermind; I found the problem -- I was looking at the wrong record (ah,
the joys of high data offsets). Records 272 and 273 look for very
similar, and I was comparing 272 in the file against 273 in the buffer.

Don't I feel stupid....

-Kevin
 
 
Daniel





PostPosted: Wed May 18 18:02:50 CDT 2005 Top

Visual C#.Net >> BinaryReader munges data
"Kevin Trojanowski" <EMail@HideDomain.com> wrote in message
news:LGPie.41666$gc6.23658@okepread04...
> Daniel O'Connell [C# MVP] wrote:
>
>> How is it munging it? And could you show us a short but complete
>> program[1] that exhibits your problem? The code below just doesn't show
>> whats going to happen.
>
> Nevermind; I found the problem -- I was looking at the wrong record (ah,
> the joys of high data offsets). Records 272 and 273 look for very
> similar, and I was comparing 272 in the file against 273 in the buffer.
>
> Don't I feel stupid....

It happens, ;).