From 726f4fccfad643b2ca4740a340b6a3429bfa2a9d Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Mon, 11 Jan 2021 19:23:44 +0100 Subject: [PATCH] Fixed empty file crawled. --- src/fr/devinsy/statoolinfos/crawl/CrawlCache.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java index ef2bd3f..e83c6d1 100644 --- a/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java +++ b/src/fr/devinsy/statoolinfos/crawl/CrawlCache.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Christian Pierre MOMON + * Copyright (C) 2020-2021 Christian Pierre MOMON * * This file is part of StatoolInfos, simple service statistics tool. * @@ -21,6 +21,7 @@ package fr.devinsy.statoolinfos.crawl; import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.Files; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; @@ -389,7 +390,17 @@ public class CrawlCache { final int TIMEOUT = 5000; result = buildFile(url.toString()); - FileUtils.copyURLToFile(url, result, TIMEOUT, TIMEOUT); + File temp = Files.createTempFile("tmp-", ".statoolsinfos").toFile(); + FileUtils.copyURLToFile(url, temp, TIMEOUT, TIMEOUT); + if (temp.length() == 0) + { + logger.warn("WARNING: empty file crawled for [{}]", url); + } + else + { + temp.renameTo(result); + } + temp.delete(); } else {