Bug 35255

Summary: davget ANT task downloads files with size 0 on slow connections
Product: Slide Reporter: Carsten Polack <polliguard-asf>
Component: WebDAV clientAssignee: Slide Developer List <slide-dev>
Status: NEW ---    
Severity: major Keywords: PatchAvailable
Priority: P2    
Version: 2.1   
Target Milestone: ---   
Hardware: All   
OS: All   
Attachments: Patch to use blocking I/O in Get task, as suggested

Description Carsten Polack 2005-06-07 16:53:28 UTC
The org.apache.webdav.ant.taskdefs.Get.copyStream(InputStream, OutputStream, 
FilterSetCollection, String) method uses java.io.InputStream.available() in 
order to determine the number of bytes to be read from the stream.

According to the documentation of java.io.InputStream.available() this 
method "Returns the number of bytes that can be read (or skipped over) from 
this input stream without blocking by the next caller of a method for this 
input stream. The next caller might be the same thread or or another thread."

As a result all downloaded files will have the size 0 if a slow connection is 
used.

Suggested solution:
Replace the existing code:
    while (in.available() > 0) {
        int cnt = in.read(b, 0, b.length);
        if (cnt > -1) {
            out.write(b, 0, cnt);
        }
    }
by:
    int cnt;
    while ((cnt = in.read(b, 0, b.length)) > 0)
    {
        out.write(b, 0, cnt);
    }
in order to read the stream until the end of the stream has been reached.
Comment 1 Martin Kal 2005-06-08 11:22:27 UTC
Created attachment 15331 [details]
Patch to use blocking I/O in Get task, as suggested

Patch to use blocking I/O in Get task, as suggested by user. Created against
SLIDE_2_1_BRANCH but should apply to HEAD as well.
Comment 2 Martin Kal 2005-06-08 11:23:33 UTC
Patch for SLIDE_2_1_BRANCH and HEAD is available.
Comment 3 wheyboer 2006-07-19 12:44:51 UTC
I had this problem although slightly different, I tried your fix but it didn't
work for me. 
Didn't see this bug (because I was lazy), but created another bugreport: 40074.
The patch thats used there definitely works.

regards,

Wim