0

I would like to send a XML file from a server to client. The XML file has been generated by the XMLEncoder class and contains some persistent objects.

The client reads the XML file by using a XMLDecoder and storing the objects in a collection, but it's not necessary to write the file to disk. Is that possible? If so, how could it be done? Thanks.

1 Answer 1

2

Is that possible? If so, how could it be done?

Read the data from the socket instead of reading from a File. XMLDecoder takes an InputStream which can be the socket.getInputSteam();

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

4 Comments

I would just add that it's recommendable to wrap the InputStream in a BufferedInputStream. new XMLDecoder(new BufferedInputStream(socket.getInputStream()));
Thank you :-) Then this is much easier than I was thinking.
@Peter I think XMLDecoder would only be able to read files encoded by XMLEncoder. We may not know what has been used on client side. So is there any other class that can take socket.getInputStream() to read XML directly?
@raghav correct, I would expect XMLDecoder to only read a subset of XML. Note: this form of serialization isn't secure either so you have to trust the source of the data.

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.