[英]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.我有一些使用 httpCore util copyURLtoFile() 复制的代码,但我似乎无法在文档中找到任何关于超时的信息,就像使用 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()如果第三行应该超时,则程序无法根据运行时抛出错误或检查 threadInterrupted()
You must be looking at old javadocs.您一定正在查看旧的 javadocs。 In the current release (2.4) here is an overload of the
copyURLToFile
method that has two timeout parameters:在当前版本 (2.4) 中,这里是具有两个超时参数的
copyURLToFile
方法的重载:
public static void copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
throws IOException
As the javadoc explains, the time unit is milliseconds.正如 javadoc 解释的那样,时间单位是毫秒。
Reference: https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html参考: https ://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils.html
Not true, the overloaded method不正确,重载的方法
FileUtils.copyURLToFile(URL source,
File destination,
int connectionTimeout,
int readTimeout)
does not exist in the latest 2.4.在最新的 2.4 中不存在。 version , although the method is listed in Javadoc:
version ,尽管该方法在 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) 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.我很确定我使用的是 2.4 版的 Apache commons-io。
PS: 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. PS:我还下载了源( http://www.carfab.com/apachesoftware//commons/io/source/commons-io-2.4-src.zip )以确保上述方法确实不存在(不再存在?) 并且在
FileUtils.java
里面真的没有这样的方法。
Check your maven dependencies, there might be another older version of common-io jar in your classpath.检查您的 maven 依赖项,您的类路径中可能还有另一个旧版本的 common-io jar。 I had the same issue.
我遇到过同样的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.