-
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");
-
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");
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks