Bug 35255 - davget ANT task downloads files with size 0 on slow connections
Summary: davget ANT task downloads files with size 0 on slow connections
Status: NEW
Alias: None
Product: Slide
Classification: Unclassified
Component: WebDAV client (show other bugs)
Version: 2.1
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: Slide Developer List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2005-06-07 16:53 UTC by Carsten Polack
Modified: 2006-07-19 05:44 UTC (History)
0 users



Attachments
Patch to use blocking I/O in Get task, as suggested (938 bytes, patch)
2005-06-08 11:22 UTC, Martin Kal
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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