Set timeout on org.apache.commons.io.FileUtils.copyURLToFile?
I have some code that copies using httpCore util copyURLtoFile() but I can't seem to find anything about timeouts in the documentation like I was able to with httpClient. The file it's pulling shouldn't pull out, but depending on that is.... interesting.
URL pjmUrl = new URL("myFile");
File projLoad = new File("projLoad.txt");
org.apache.commons.io.FileUtils.copyURLToFile(pjmUrl, projLoad);
If the third line should timeout, the program has no way to throw an error based on runtime or to check for threadInterrupted()
Solution 1:
You must be looking at old javadocs. In the current release (2.4) here is an overload of the copyURLToFile
method that has two timeout parameters:
public static void copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
throws IOException
As the javadoc explains, the time unit is milliseconds.
Reference: https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html
Solution 2:
Not true, the overloaded method
FileUtils.copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
does not exist in the latest 2.4. version, although the method is listed in Javadoc:
http://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/FileUtils.html#copyURLToFile(java.net.URL,%20java.io.File,%20int,%20int)
I'm positively sure that I'm using the 2.4 version of Apache commons-io.
P.S.: I also downloaded source (http://www.carfab.com/apachesoftware//commons/io/source/commons-io-2.4-src.zip) to make sure that the above method really doesn't exist (anymore?) and inside FileUtils.java
there really isn't such method.