Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Advanced-java] C-like structs?
- From: jboyd@xxxxxx (Jason Boyd)
- Subject: [Advanced-java] C-like structs?
- Date: Thu, 28 Feb 2002 14:14:45 -0500 (EST)
In C/C++, a common way to serialize data is to define a struct containing
data in the exact packed format it would be on disk, and then (in
pseudo-code) do this:
typedef struct MYDATA {
int x, y;
double wx, wy;
} * MYDATAptr;
MYDATA data; // ... fill with actual data
...
FILE file = open(filename);
file.write(data, sizeof(MYDATA));
file.close();
OR:
file.read(&data, sizeof(MYDATA));
Is there a way to do this in Java? That is, simply read from an input
stream or write into an output stream the raw data of a class without
having to write serialization code?
The reason is that I need to read heavily nested legacy files (written by
a C app) which are entirely based on this paradigm, and which use a *lot*
of different struct types.
Maybe I'm missing an obvious idiom, but I haven't seen a simple way to do
this in Java... Anyone?
Jason
- Follow-Ups:
- [Advanced-java] C-like structs?
- From: Jose Ortiz
- [Advanced-java] C-like structs?
- Prev by Date: [Advanced-java] Mystery no more!
- Next by Date: [Advanced-java] C-like structs?
- Previous by thread: [Advanced-java] Mystery no more!
- Next by thread: [Advanced-java] C-like structs?
- Index(es):