Re: Buffered reading seems to corrupt data stream
- From: Peter Duniho <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Mon, 03 Oct 2011 08:44:59 -0700
On 10/3/11 7:58 AM, Qu0ll wrote:
[...]
The problem is that for the second or third read, the size variable is
coming back as garbage (extremely high or even negative value) and the
reading of the byte array blocks as it waits for a large amount of data
to be received or crashes with the invalid negative size even though the
previous size value and the previous bytes themselves are correct.
However, if I remove the BufferedInputStream wrapping of stream, it
works perfectly.
Why would that be?
If you don't post a concise-but-complete code example that reliably reproduces the problem (i.e. an SSCCE), there's no way to answer that question.
The problem you are describing is typical of failure to treat the streams as streams, but of course that's the kind of thing that DataInputStream is supposed to address for you (and which I believe will, as long as you use it correctly…unless perhaps you're using some odd-ball Java implementation that might be more buggy than the ones you'd usually find on mainstream OSs).
Another way I suppose you could observe the behavior you're describing is to be using a datagram socket instead of a stream-oriented socket.
But without a proper code example, there's no way to know what you've done wrong.
Pete
.
- References:
- Buffered reading seems to corrupt data stream
- From: Qu0ll
- Buffered reading seems to corrupt data stream
- Prev by Date: Re: Buffered reading seems to corrupt data stream
- Next by Date: Re: Buffered reading seems to corrupt data stream
- Previous by thread: Re: Buffered reading seems to corrupt data stream
- Next by thread: Re: Buffered reading seems to corrupt data stream
- Index(es):
Relevant Pages
|