Monday, 15 June 2015

stream - Java - Is ObjectInput/OutputStream compatible with DataInput/OutputStream? -



stream - Java - Is ObjectInput/OutputStream compatible with DataInput/OutputStream? -

for example:

i send byte[] on socket outputstream using objectinput/outputstream:

objectoutputstream myoutput = new objectoutputstream(mysocket.getoutputstream()); myoutput.write(mybytearray);

at other end, utilize datainputstream (and may utilize other inputstream well) read:

datainputstream hisinput = new datainputstream(hissocket.getinputstream()); hisinput.read(hisbytearray);

so question is:

will receiver read byte[] correctly? what string using writeobject , readutf?

info:

i can utilize java library (jre8) , new java's stream. i can not expect or forcefulness other side utilize stream other knowing not using objectinput/outputstream i asked question because using objectinput/outputstream may save me work, took advice other question.

will receiver read byte[] correctly?

no.

what string using writeobject , readutf?

no.

if utilize objectoutputstream.writeobject write, practical way read stream using objectoutputstream.readobject.

in theory, write code implement serialization protocol (using byte or "data" input streams), not sensible / practical approach.

i can not expect or forcefulness other side utilize stream other knowing not using objectinput/outputstream

whatever utilize format when write, forcing other end utilize capable of reading it. forcing other end (if java) utilize objectinputstream should not concern. matter if other end implemented in language, should considering json or xml encoding scheme.

java stream

No comments:

Post a Comment