Object serialization

I am wondering how this occurs. I am using some java code which uses the write_object function of a class which does not implement the serializable interface. I am not allowed to change that particular class in any way because it is already in production and I cannot distribute a new version as I would like.

What I need to do is read the object from the output file with C/C++. Sadly, I am not sure how I can read the object via write_object.In java it works fine, but sadly I will not be using java to reconstitute the object. Any ideas on how to read the object? Any hints would be wonderful, thanks.

[618 byte] By [dpro19792a] at [2007-10-2 10:37:34]
# 1

I know you already said you can't do this, but you likely don't want to read objects written via writeObject with anything other than readObject. The format could change out from underneath you, and the overhead might be more than you care to deal with. But since you seem to have no choice, curl up with this

http://java.sun.com/j2se/1.4/pdf/serial-spec.pdf

And good luck to you

Lee

tsitha at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 2

> I am wondering how this occurs. I am using some java

> code which uses the write_object function of a class

> which does not implement the serializable interface.

> I am not allowed to change that particular class in

> n any way because it is already in production and I

> cannot distribute a new version as I would like.

>

> What I need to do is read the object from the output

> file with C/C++. Sadly, I am not sure how I can read

> the object via write_object.In java it works fine,

> but sadly I will not be using java to reconstitute

> the object. Any ideas on how to read the object?

> Any hints would be wonderful, thanks.

Are you required to use Java serialization to pass the object through a file? You could use language-independent serialization solutions, for instance serialize to XML.

Lokoa at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 3

That could be a problem, I am reading that at the moment.

Basically its a production Applet which I am not allowed to touch in any way ( I have the source, but again am not allowed to distribute).

In reading the API, it seems the object is an IDL CORBA object, however I am not sure what to do with it.

Basically the calls are:

class Cell

{

//protected data etc...

};

then another Class, calls read/write object ( their own )...

Using an array: Cell cells[n][m]

public boolean write_object( DataOutputStream stream )

{

...

for( int i = 0; i < rows; i++ )

{

for( int j = 0; j < cols; j++ )

{

if( ! cells[i][j].write_object(stm) )

return false;

}

}

}

This is what I am looking at. Then I have to read the file via a program I am writing (not java), any other sources I could look into. I am currently not seeing anything in that pdf, but I will keep reading it over and seeing what I can glean from it.

dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 4
well, what exactly does the write_object method of the Cell class do? If it just writes out some state in some reasonable format then you can read that.
tsitha at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 5

Well that was stupid, upon further inspection the write_object method and read_object always return true...

public boolean read_object(DataInputStream stream)

{

// nothing output

return true; // important!

}

so I guess I was stressing over something that always succeeds and never reads in anything... *sigh* the person who wrote this needs to be shot... no comments or anything and he is long gone. Thanks for helping if nothing else.

dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 6
Um, that is going to make it a bit more difficult to read the data into your non-Java sysytem, however.Good luckLee
tsitha at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 7
Thats true, but at least I know one avenue I cannot go. Thanks for at least checking it out :)
dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 8

So to reopen this question a bit, would it be possible (although somewhat cumbersome) to write a java app, which takes the objects in the file, is executed by c++ code, and either writes them in plain (easily parsible text) or converts them in some easy to parse way? I assume this is entirely possible?

dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 9

I may well be missing something, but if it is a CORBA object, why don't you access it from C++ as such? CORBA is a language and platform independant protocol for object level program interoperability. There are implementations for Java and C++ and other languages as well. Why do you have to comminicate by means of writing/reading a file?

Lokoa at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 10

Sadly its because of the way the applet server is setup, you interact with it, and write the file, which is then interpreted later on to get the information. We need it to be written because it is loaded later on into a different app which parses the file. I may be able to get the source of the other program and figure out how they load it, but any further ideas would be great. Its just the constraints I am working with sadly.

dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 11

> Sadly its because of the way the applet server is

> setup, you interact with it, and write the file,

I may well have missed something as well, but didn't you discover that you don't, in fact, write this file? And didn't you say that you cannot change the source? If this is the case, you're done, right?

> which is then interpreted later on to get the

> information. We need it to be written because it is

> loaded later on into a different app which parses the

> file. I may be able to get the source of the other

> program and figure out how they load it, but any

> further ideas would be great. Its just the

> constraints I am working with sadly.

tsitha at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 12
oh wait, it was the *read* method, not the write method - so, what does the write_object method of the Cell class do?
tsitha at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...
# 13

Thats the funny (or not so funny part), the cell class provides no way to read or write the object, both simply return true. However, it is somewhere withing the source, since they are displayed in the program itself. It is somewhere within the 60 java source files, but as of now I cannot find the method. I will keep looking. for it as I go here. Not the best designed program sadly.

dpro19792a at 2007-7-13 2:42:11 > top of Java-index,Java Essentials,Java Programming...