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


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

Re: Buffered reading seems to corrupt data stream

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.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!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
From Lew <lewbloch@gmail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Buffered reading seems to corrupt data stream
Date Tue, 4 Oct 2011 08:48:20 -0700 (PDT)
Organization http://groups.google.com
Lines 38
Message-ID <19587162.2005.1317743300210.JavaMail.geo-discussion-forums@prfh23> (permalink)
References <y4Cdne-uvN4kUBTTnZ2dnUVZ_hWdnZ2d@westnet.com.au> <j6cv50$2fk$2@dont-email.me>
Reply-To comp.lang.java.programmer@googlegroups.com
NNTP-Posting-Host 65.50.220.43
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-Trace posting.google.com 1317743314 3269 127.0.0.1 (4 Oct 2011 15:48:34 GMT)
X-Complaints-To groups-abuse@google.com
NNTP-Posting-Date Tue, 4 Oct 2011 15:48:34 +0000 (UTC)
In-Reply-To <j6cv50$2fk$2@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=65.50.220.43; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T
User-Agent G2/1.0
X-Google-Web-Client true
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8528

Show key headers only | View raw


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) without 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 mean 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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next 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