0

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.

0

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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..

2 Comments

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.
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..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.