views:

15

answers:

3

I'm trying to read a file that was created in a Java-based game using ObjectOutputStream in PHP. The data is a serialized object written in a binary format.

I've been using fopen and fread to get the binary data, but I have absolutely no idea what to do with it.

A: 

You can't do it so easily (unless an existing framework is available). This because the binary format used by Java serialization is highly specialized to the JVM, think that there's not guaranteed compatibility even between different JVM versions.

You should use a different approach, for example using XML, YAML or JSON..

Jack
The problem I'm having is that the file I'm trying to read isn't generated by anything I've personally created. So unless I can convince the author of the program that creates these files to switch to XML I'm stuck trying to read the Java-generated file.
Jeff
Then you need a middleware written in Java that is able to convert the serialized object, I don't think there are any other human ways..
Jack
Hmm, that's a good idea. I'll try that out, thanks.
Jeff
+3  A: 

PHP doesn't understand Java. Both do however understand a common format like JSON, XML, CSV, etc. I'd suggest to change the format to either of them and use that as data transfer format instead.

In case of JSON, you can in Java use Google Gson to convert (encode) fullworthy javabeans into JSON flavor and in PHP you can use json_decode() to convert (decode) it into an associative PHP array.

BalusC
A: 

It doesn't seem easy to reimplement http://download.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html

mario