Reputation: 21
How can I count the number of bytes written by Appache Commons FileUtils.copyURLToFile
?
Upvotes: 1
Views: 309
Reputation: 1667
Since copying file from url takes time and you already have Apache Commons on your classpath, you might want to use ConcurrentUtils
class for your problem.
long lengthInBytes = ConcurrentUtils.constantFuture(downloadFile()).get();
where downloadFile()
method provides an implementation, which returns length of file in bytes
public Long downloadFile() throws IOException {
File target = new File(fileName);
FileUtils.copyURLToFile(new URL(url), target);
return target.length();
}
Upvotes: 1