Problem w/ JSWDK1.0.1 & ServletInputStream.readLine()


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Problem w/ JSWDK1.0.1 & ServletInputStream.readLine()

  1. #1
    Al Guest

    Problem w/ JSWDK1.0.1 & ServletInputStream.readLine()


    Hello all. I'm having a problem making a servlet to upload a file.
    ServletInputStream.readLine(bytes[],int,int) is supposed to return -1 once
    the incoming file is all read.
    However, the following code gets stuck in the while loop (specifically it
    looks like it gets stuck in the readLine method). It does not print the "out
    of while" statement until the browser which is uploading the file times out.


    Is there a problem in JSWDK1.0.1 with the implementation of ServletInputStream.readLine()??


    *************************************************
    ....
    int result=0;
    ServletInputStream in = request.getInputStream();
    byte[] b = new byte[8192];
    while ((result = in.readLine(b,0,b.length)) != -1)
    {
    System.out.println(result);
    }
    System.out.println("Out of while");

  2. #2
    Jo Desmet Guest

    Re: Problem w/ JSWDK1.0.1 & ServletInputStream.readLine()

    Maybe the problem is on the client side, that is if you are using java code
    to connect to your servlet. If this is the case then it is possible that
    your servlet is waiting for an EOF because the stream on the client side is
    not yet properly flushed and closed. This can happen if the user depends on
    the grabage collector to do this, resulting the stream to be open for an
    unspeciefied time of amount (until the garbage collector decides to clean
    up).

    "Al" <abencomo@webtonetech.com> wrote in message
    news:3980598f$1@news.devx.com...
    >
    > Hello all. I'm having a problem making a servlet to upload a file.
    > ServletInputStream.readLine(bytes[],int,int) is supposed to return -1 once
    > the incoming file is all read.
    > However, the following code gets stuck in the while loop (specifically it
    > looks like it gets stuck in the readLine method). It does not print the

    "out
    > of while" statement until the browser which is uploading the file times

    out.
    >
    >
    > Is there a problem in JSWDK1.0.1 with the implementation of

    ServletInputStream.readLine()??
    >
    >
    > *************************************************
    > ...
    > int result=0;
    > ServletInputStream in = request.getInputStream();
    > byte[] b = new byte[8192];
    > while ((result = in.readLine(b,0,b.length)) != -1)
    > {
    > System.out.println(result);
    > }
    > System.out.println("Out of while");




  3. #3
    Eugene Shershnev Guest

    Re: Problem w/ JSWDK1.0.1 & ServletInputStream.readLine()


    Try this:

    int result=0;
    ServletInputStream in = request.getInputStream();
    byte[] b = new byte[8192];
    while ((result = in.readLine(b,result,b.length)) != -1)
    {
    System.out.println(result);
    }
    System.out.println("Out of while");

    I think you're reading the beginning of the file every time. You have to
    move to the next block in your while loop when you read the next line.


    "Jo Desmet" <jo_desmet@yahoo.com> wrote:
    >Maybe the problem is on the client side, that is if you are using java code
    >to connect to your servlet. If this is the case then it is possible that
    >your servlet is waiting for an EOF because the stream on the client side

    is
    >not yet properly flushed and closed. This can happen if the user depends

    on
    >the grabage collector to do this, resulting the stream to be open for an
    >unspeciefied time of amount (until the garbage collector decides to clean
    >up).
    >
    >"Al" <abencomo@webtonetech.com> wrote in message
    >news:3980598f$1@news.devx.com...
    >>
    >> Hello all. I'm having a problem making a servlet to upload a file.
    >> ServletInputStream.readLine(bytes[],int,int) is supposed to return -1

    once
    >> the incoming file is all read.
    >> However, the following code gets stuck in the while loop (specifically

    it
    >> looks like it gets stuck in the readLine method). It does not print the

    >"out
    >> of while" statement until the browser which is uploading the file times

    >out.
    >>
    >>
    >> Is there a problem in JSWDK1.0.1 with the implementation of

    >ServletInputStream.readLine()??
    >>
    >>
    >> *************************************************
    >> ...
    >> int result=0;
    >> ServletInputStream in = request.getInputStream();
    >> byte[] b = new byte[8192];
    >> while ((result = in.readLine(b,0,b.length)) != -1)
    >> {
    >> System.out.println(result);
    >> }
    >> System.out.println("Out of while");

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center