简体   繁体   English

在 org.apache.commons.io.FileUtils.copyURLToFile 上设置超时?

[英]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.

相关问题 Commons IO(Apache)copyURLToFile不起作用 - Commons IO (Apache) copyURLToFile Not Working org / apache / commons / io / FileUtils-NoClassDefFoundError - org/apache/commons/io/FileUtils - NoClassDefFoundError 如何在Servlet中改善org.apache.commons.io.FileUtils copyInputStreamToFile - How to improve org.apache.commons.io.FileUtils copyInputStreamToFile in Servlet 缺少方法 org.apache.commons.io.FileUtils.forceMkdirParent? - missing methode org.apache.commons.io.FileUtils.forceMkdirParent? org.apache.commons.io.FileUtils-更改文本编码 - org.apache.commons.io.FileUtils - change text encodig org.apache.commons.io.FileUtils.readFileToString 和文件路径中的空白 - org.apache.commons.io.FileUtils.readFileToString and blanks in filepath 分叉进程 org/apache/commons/io/FileUtils org.apache.maven.surefire.booter.SurefireBooterForkException 中出现错误 - There was an error in the forked prpcess org/apache/commons/io/FileUtils org.apache.maven.surefire.booter.SurefireBooterForkException java.lang.NoSuchMethodError : org.apache.commons.io.FileUtils.isSymLink(Ljava/io/File;)Z - java.lang.NoSuchMethodError : org.apache.commons.io.FileUtils.isSymLink(Ljava/io/File;)Z Java库,例如org.apache.commons.io.FileUtils,但包含实例方法而不是静态方法 - Java library like org.apache.commons.io.FileUtils but contains instance methods instead of static methods 使用org.apache.commons.io.FileUtils时Android内存泄漏 - Android memory leak when using org.apache.commons.io.FileUtils
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM