Re: Buffered reading seems to corrupt data stream
markspace wrote:
Qu0ll wrote:
I am trying to repeatedly send a byte array from a server to a client
where both the writing and the reading is done in a buffered manner with
the following code on the server:
DataOutputStream dos = new DataOutputStream(os);
dos.writeInt(bytes.length);
dos.write(bytes);
dos.flush();
I got to repeat the request for an SSCCE. The code above is certainly
not where the problem is. The problems is certainly in some other area=
which you haven't shown us.
As a suggestion, scan the input above before you write it. You'll
certainly find the same values going in as you are reading back out.
Then trace the path up the input side to determine what is actually
writing that data in the the array "bytes".
Just this once the question was answerable (and answered, elsethread) witho=
ut the SSCCE, but truthfully the respondents had to infer the context that =
an SSCCE would've made explicit. They just happened to guess right. (Well=
, it was fairly obvious.)
But to the OP and the rest of us, it really is a good idea to package your =
example as an SSCCE. Just because we think something is obvious doesn't me=
an everyone does.
Coincidentally I was just facing the same problem in a project. I want to =
independently dip into an input stream without trashing the stream location=
by buffering. In my case I did away with the buffering, but for the OP's =
case here it is much easier to preserve the stream at wider scope than they=
originally had it.
--
Lew