473,383 Members | 1,859 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,383 software developers and data experts.

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);
}
}
Nov 17 '05 #1
3 1305

"Kevin Trojanowski" <tr**@nospam.cox.net> 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

Nov 17 '05 #2
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
Nov 17 '05 #3

"Kevin Trojanowski" <tr**@nospam.cox.net> 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, ;).
Nov 17 '05 #4

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

Similar topics

0
by: Denny Rue | last post by:
I’ve created VB code to download files from a web site through the use of HTTPWebRequest, HTTPWebResponse and BinaryReader. The HTTPWebRequest has a TimeOut property to limit how long it waits...
1
by: gladiator | last post by:
Hello MVPs: I am not sure when to use binaryreader in .net is best? In fact ,I am coding a program which converts data in text files into DB. but i have to use fixed length to read data in...
4
by: Paul Steele | last post by:
I am writing a client/server application that communicates over tcp. The code I use to initiate the connection is as follows: NetworkStream networkStream = new NetworkStream(ClientSocket);...
6
by: Question with BinaryReader | last post by:
I use BinaryReader to read my binary dafa files, when i call ReadBytes, why it always return more 4 bytes. The following is my code. FileStream fs = new FileStream(file, FileMode.OpenOrCreate,...
1
by: Vitaly | last post by:
// Open input file and create the BinaryReader. br = new BinaryReader(new FileStream("Test.dat", FileMode.Open, FileAccess.Read)); // Read binary data. d = br.ReadDouble(); A question is...
2
by: I_AM_DON_AND_YOU? | last post by:
Can BinaryReader Object read the Word file?
1
by: Gintautas | last post by:
Hi I'm trying to make read binary file to the data array, but a problem is that the user is choosing either to read 1 byte(sbyte) or 2 bytes(Int16). So i need to make smth universal. My code:...
9
by: Drayshak | last post by:
Hi, I'm currently making an application which reads a file and extracts information from it. Whole files are embedded in this single file, and information about each file that is embedded is...
3
by: =?Utf-8?B?VmljdG9y?= | last post by:
Hi, Could you tell me can I keep the MemoryStream open and "close" the BinaryReader? As the MemoryStream is used for buffering the TCP data and BinaryReader is only used to read the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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.