Article View: borland.public.jbuilder.java.language
Article #17585RandomAccessFile Problems (Reading in C structures from file)
From: Shane Warren
Date: Wed, 21 Oct 1998 00:00
Date: Wed, 21 Oct 1998 00:00
23 lines
1898 bytes
1898 bytes
I'm having problems figuring out how to read in a file written using a C++ program. The file is a sort of ring buffer that has a header at the beginning of the file, and then the ring buffer is after that. The header is a C structure that has a lot of fields in it. I need a way to first be able to read that header into a header on the java side which is a class that is just like the C struct. RandomAccessFiles read(byte[]) is what I thought I could use by typecasting my java class that I want to fill in to a byte[], but the typecast won't go. Please don't tell me I'll have to fill in each field of that class with an individual call like ReadInt, ReadLong, etc. That would seem to be really inefficient, and not to mention unnecessary coding. I also need to be able get the size of the header (I used sizeof in C) so I can seek forwards and backwards in the ring buffer. I could calculate the size of this class (struct) myself but first of all it has a lot of elements and one of the elements is another structure which has a lot of elements itself, and second of all what if the structure size changes (and it most certainly will) then I have to recalculate this all over again, why the hell isn't there a sizeof function just for this reason (and more that I've run into)? Java isn't looking to be able to do what I could do in C with no problems, what gives here?
Technical Details
Message-ID:
<70ma3b$jab10@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,2afc15a8a343a958,start X-Google-Attributes: gidf74b3,public From: "Shane Warren" <swarren@rapidnet.com> Subject: RandomAccessFile Problems (Reading in C structures from file) Date: 1998/10/21 Message-ID: <70ma3b$jab10@forums.borland.com> X-Deja-AN: 403799663 Organization: Another Netscape Collabra Server User X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Newsgroups: borland.public.jbuilder.java.language