🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7278

Stream Copier

#7278
From: Francisco Gongora
Date: Fri, 29 Jun 2001 13:46
34 lines
1979 bytes
Hi Folks:
I am trying to read an HTML request from a browser and pipe it to a Web
Server, then do the same with the server's response back to the browser.  I
have a stream copier method to fast copy input to output streams and vice
versa:

public static void copy(InputStream in, OutputStream out) throws
IOException{
    synchronized( in ) {
      synchronized( out ) {
        BufferedInputStream bin= new BufferedInputStream( in );
        BufferedOutputStream bout= new BufferedOutputStream( out );

        while(true) {

          int datum = bin.read();
          System.out.println( "bytesRead : " +datum );
          if (datum == -1) break;
          bout.write(datum);

        }
        bout.flush();
        System.out.println( " flushing: "  );
      }
    }
}

Based on API description for InputStream, read() returns the number of bytes
actually read, or -1 on the end of the stream.  However, in the above method
the datum read never gets -1, so it never breaks the while.
Could anyone explain me what the problem is.  Is it there any alternative to
this approach?
Thanks.
Francisco
Technical Details
Message-ID: <3b3c86a5_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,e27c87a03f03f160,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-06-29 06:48:58 PST
Reply-To: "Francisco Gongora" <fgongora@metilinx.com>
From: "Francisco Gongora" <fgongora@metilinx.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: Stream Copier
Date: Fri, 29 Jun 2001 09:46:03 -0400
Lines: 37
Organization: Metilinx
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 65.160.52.2
Message-ID: <3b3c86a5_2@dnews>
X-Trace: dnews 993822373 65.160.52.2 (29 Jun 2001 06:46:13 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews