3 Replies Latest reply on Jun 25, 2007 2:38 AM by EJP


      Hi guys,

      What I need to know is a way of knowing when the stream has been al read.
                     Reader objReader = new BufferedReader(new InputStreamReader(this.objInputStream));
                     byteContent = new byte[this.objInputStream.available()];
      The ready method returns true as soon as some data arrive thus, I don't really know how to do this, can you guys point me some directions.

      Many Thanks,

        • 1. Re: InputStreamReader
          Try this.

          String line = null;
          BufferedReader br = new BufferedReader(your stuff here);
          while((line = br.readLIne()) != null) {
          //do your work

          br.readLine() will return a null when the end of the stream is reached, Or if you're using the various read calls, they will return the number of bytes that have been read, and will return -1 when the end of the stream is reached.

          You have to be careful with this if you're doing network io for example, because the call to read can return 0 bytes, but still not be closed. :-)
          • 2. Re: InputStreamReader
            Thanks for your reply billrobertson42,

            but there are two things:

            - I don't know whether the server will or not, send the end of lne,
            - I don't know the length of the stream.

            So if the server doesn't write the carriage return to the outputStream the loop will continue indefinitely.


            • 3. Re: InputStreamReader
              read() returns -1
              readLine() returns null
              readXXX() throws EOFException