binaryreader

What is the Best way to deserialize a null-terminated string in .NET?

I am reading a message from my network connection which is serialized as a series of null-terminated strings (and other binary data) I could read a char at a time using a BinaryReader, until I find a NULL. Is there a more efficient way that is still simple? I'm expecting strings less than 64 chars in length, but they could be longer. ...

c# - reading from binary log file that is updated every 6 seconds with 12k of data

I have a binary log file with streaming data from a sensor (Int16). Every 6 seconds, 6000 samples of type Int16 are added, until the sensor is disconnected. I need to poll this file on regular intervals, continuing from last position read. Is it better to a) keep a filestream and binary reader open and instantiated between readings b) ...

Inconsistency in file before and after upload to Oracle DB

Hi, I'm trying to get my website to allow users to upload various files (HttpPostedFile), which are then stored in an Oracle database as BLOBs. Here's what I've got so far: public static bool insertFile(int pid, HttpPostedFile file, string filedesc) { string filename = file.FileName.Remove(0, file.FileName.LastIndexOf("\...

Faster (unsafe) BinaryReader in .NET

I came across a situation where I have a pretty big file that I need to read binary data from. Consequently, I realized that the default BinaryReader implementation in .NET is pretty slow. Upon looking at it with Reflector I came across this: public virtual int ReadInt32() { if (this.m_isMemoryStream) { MemoryStream str...

Converting from byte[] to string

Hi, I have the following code: using (BinaryReader br = new BinaryReader( File.Open(FILE_PATH, FileMode.Open, FileAccess.ReadWrite))) { int pos = 0; int length = (int) br.BaseStream.Length; while (pos < length) { b[pos] = br.ReadByte(); pos++; } pos = 0; while (pos < length) { ...

0x00 in a binary file VB.NET

UPDATED BELOW I am reading a Binary file using BinaryReader in VB.NET. The structure of each row in the file is: "Category" = 1 byte "Code" = 1 byte "Text" = 60 Bytes Dim Category As Byte Dim Code As Byte Dim byText() As Byte Dim chText() As Char Dim br As New BinaryReader(fs) Category = br.ReadByt...

Is there a BinaryReader in C++ to read data written from a BinaryWriter in C#?

I've written several ints, char[]s and the such to a data file with BinaryWriter in C#. Reading the file back in (in C#) with BinaryReader, I can recreate all of the pieces of the file perfectly. However, attempting to read them back in with C++ yields some scary results. I was using fstream to attempt to read back the data and the ...

C# BinaryReader "stream does not support seek operations"

I am trying to download files from an ftp server using C# and ftpwebrequest. I can get the bytes using BinaryReader, but when I try to read the stream using br.ReadBytes(int), I get an error that BinaryReader does not support seek operations. Does anyone know how best to read the bytes so I can write them to a file? Here's the full m...

Strange problem when trying to read data

When I write: var tagType = _reader.ReadByte(); while (tagType != 8) { var skip = ReadNext3Bytes() + 11; _reader.BaseStream.Position += skip; tagType = _reader.ReadByte(); } ...it's working, but when I write: var tagType = _reader.ReadByte(); while (tagType != 8) { _reader.BaseStream.Position += ReadNext3Bytes() + ...

Issue with C#/.NET BinaryReader.ReadChars()

Hi all, I've run into what I believe is an issue with the BinaryReader.ReadChars() method. When I wrap a BinaryReader around a raw socket NetworkStream occasionally I get a stream corruption where the stream being read gets out of sync. The stream in question contains messages in a binary serialisation protocol. I've tracked this dow...

EndianBinaryReader - Contious update of the input stream?

I am trying to use the EndianBinaryReader and EndianBinaryWriter that Jon Skeet wrote as part of his misc utils lib. It works great for the two uses I have made of it. The first reading from a Network Stream (TCPClient) where I sit in a loop reading the data as it comes in. I can create a single EndianBinaryReader and then just dispos...

Excel 2007 file writer in C# results in a corrupt file

Hi, I am using a BinaryReader to read an Excel 2007 file from an Exchange mailbox using a OWA, the file is then written to disk using a BinaryWriter. My problem is that the two files don't match when the writer finishes. Worse still Excel 2007 won't open the writen file. Previously Excel 2003 has had no problem with the solution belo...

C# Process Binary File, Multi-Thread Processing

I have the following code that processes a binary file. I want to split the processing workload by using threads and assigning each line of the binary file to threads in the ThreadPool. Processing time for each line is only small but when dealing with files that might contain hundreds of lines, it makes sense to split the workload. My q...

What is the best way to read the uploaded files from Request.Files, StreamReader or BinaryReader or BufferedStream?

I have a form where the user can upload multiple files. I am using MVC 2.0 and in my controller I need to call a webservice that is a common import interface requires the files to passed in as byte[]. .NET exposes Request.Files as a HttpFileCollectionBase and I access the filehandle using HttpPostedFile or HttpPostedFileBase that provid...

How to properly read 16 byte unsigned integer with BinaryReader

I need to parse a binary stream in .NET to convert a 16 byte unsigned integer. I would like to use the BinaryReader.ReadUIntXX() functions but there isn't a BinaryReader.ReadUInt128() function available. I assume I will have to roll my own function using the ReadByte function and build an array but I don't know if this is the most effi...

Performance: use a BinaryReader on a MemoryStream to read a byte array, or read directly?

I would like to know whether using a BinaryReader on a MemoryStream created from a byte array (byte[]) would reduce performance significantly. There is binary data I want to read, and I get that data as an array of bytes. I am currently deciding between two approaches to read the data, and have to implement many reading methods accordin...

How do I read shorts from a binary file starting at position x, for y values?

I need to read a certain amount of short (int16) data points from a binary file, starting at a specific position. Thanks! ...

I have written the exact code in vb and C# and it doesnt work the same... logic is identical... i hope

Kind of new to C# and trying to broaden my abilities a bit. I have this code in VB: Private Sub BreakdownFilesToCompare(ByRef file1BReader As BinaryReader, _ ByRef file2BReader As BinaryReader, _ ByRef firstFile As StandardFormatFile, _ ...

Reading in a binary file containing an unknown quantity of structures (C#)

Ok, so I currently have a binary file containing an unknown number of structs like this: private struct sTestStruct { public int numberOne; public int numberTwo; public int[] numbers; // This is ALWAYS 128 ints long. public bool trueFalse; } So far, I use the following to read all the structs into a List<>: List<sTest...

Reading custom binary data formats in C# .NET

Hi, I'm trying to write a simple reader for AutoCAD's DWG files in .NET. I don't actually need to access all data in the file so the complexity that would otherwise be involved in writing a reader/writer for the whole file format is not an issue. I've managed to read in the basics, such as the version, all the header data, the section l...