Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #8489

Buffered reading seems to corrupt data stream

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.westnet.com.au!news.westnet.com.au.POSTED!not-for-mail
NNTP-Posting-Date Mon, 03 Oct 2011 09:59:05 -0500
From "Qu0ll" <Qu0llSixFour@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Buffered reading seems to corrupt data stream
Date Tue, 4 Oct 2011 01:58:41 +1100
MIME-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding 7bit
X-Priority 3
X-MSMail-Priority Normal
Importance Normal
X-Newsreader Microsoft Windows Live Mail 15.4.3538.513
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3538.513
Message-ID <y4Cdne-uvN4kUBTTnZ2dnUVZ_hWdnZ2d@westnet.com.au> (permalink)
Lines 36
X-Usenet-Provider http://www.giganews.com
NNTP-Posting-Host 124.168.28.143
X-Trace sv3-K8h8ellJvmKK7wXd03A4vBNnEP9NfauLotmcfojr8QeZTyoC5Z5yxjVD2x3EwdNKQ7rVwVMYg/PYhh1!7kYMuHUr0T1Kx5ucwrhQfER1bJuL6joY282+7dg2jkzvfiLa5PatajCjD9qErXkSZVx2qyCDnabL!5pDN8G9NIruiwA9sy9Kiig==
X-Complaints-To abuse@westnet.com.au
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 2457
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8489

Show key headers only | View raw


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();

and this on the client:

System.out.println("Reading size...");
final DataInputStream dis = new DataInputStream(new 
BufferedInputStream(is));
final int size = dis.readInt();
final byte[] bytes = new byte[size];
System.out.println("Reading " + size + " bytes...");
dis.readFully(bytes);

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?

--
And loving it,

-Qu0ll (Rare, not extinct)
_________________________________________________
Qu0llSixFour@gmail.com
[Replace the "SixFour" with numbers to email me] 

Back to comp.lang.java.programmer | Previous | NextNext in thread | Find similar


Thread

Buffered reading seems to corrupt data stream "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-10-04 01:58 +1100
  Re: Buffered reading seems to corrupt data stream "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-10-04 02:26 +1100
    Re: Buffered reading seems to corrupt data stream Ronny Schütz <usenet.r96@gishpuppy.com> - 2011-10-03 17:54 +0200
      Re: Buffered reading seems to corrupt data stream "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-10-04 07:07 +1100
        Re: Buffered reading seems to corrupt data stream Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-10-03 13:18 -0700
      Re: Buffered reading seems to corrupt data stream "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-10-04 10:54 +1100
    Re: Buffered reading seems to corrupt data stream Roedy Green <see_website@mindprod.com.invalid> - 2011-10-03 11:46 -0700
  Re: Buffered reading seems to corrupt data stream Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-10-03 08:44 -0700
  Re: Buffered reading seems to corrupt data stream markspace <-@.> - 2011-10-03 11:33 -0700
    Re: Buffered reading seems to corrupt data stream Lew <lewbloch@gmail.com> - 2011-10-04 08:48 -0700
      Re: Buffered reading seems to corrupt data stream Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-10-04 09:07 -0700
        Re: Buffered reading seems to corrupt data stream Lew <lewbloch@gmail.com> - 2011-10-04 12:06 -0700

csiph-web