diff --git a/source/net/yacy/crawler/retrieval/FileLoader.java b/source/net/yacy/crawler/retrieval/FileLoader.java index cf0b683e7..12e809914 100644 --- a/source/net/yacy/crawler/retrieval/FileLoader.java +++ b/source/net/yacy/crawler/retrieval/FileLoader.java @@ -137,7 +137,6 @@ public class FileLoader { // load the resource InputStream is = url.getInputStream(ClientIdentification.yacyInternetCrawlerAgent, null, null); byte[] b = FileUtils.read(is); - is.close(); // create response with loaded content final CrawlProfile profile = this.sb.crawler.get(ASCII.getBytes(request.profileHandle())); diff --git a/source/net/yacy/crawler/retrieval/SMBLoader.java b/source/net/yacy/crawler/retrieval/SMBLoader.java index 67e3fdee1..8de78c8b0 100644 --- a/source/net/yacy/crawler/retrieval/SMBLoader.java +++ b/source/net/yacy/crawler/retrieval/SMBLoader.java @@ -155,7 +155,6 @@ public class SMBLoader { // load the resource InputStream is = url.getInputStream(ClientIdentification.yacyInternetCrawlerAgent, null, null); byte[] b = FileUtils.read(is); - is.close(); // create response with loaded content final CrawlProfile profile = this.sb.crawler.get(request.profileHandle().getBytes()); diff --git a/source/net/yacy/kelondro/util/FileUtils.java b/source/net/yacy/kelondro/util/FileUtils.java index 37e7b94d9..4e78cb69f 100644 --- a/source/net/yacy/kelondro/util/FileUtils.java +++ b/source/net/yacy/kelondro/util/FileUtils.java @@ -268,8 +268,24 @@ public final class FileUtils { copy(new ByteArrayInputStream(source), dest); } + /** + * Read fully source stream and close it. + * @param source must not be null + * @return source content as a byte array. + * @throws IOException when a read/write error occured + */ public static byte[] read(final InputStream source) throws IOException { - return read(source, -1); + byte[] content; + try { + content = read(source, -1); + } finally { + /* source input stream must be closed here in all cases */ + try { + source.close(); + } catch(IOException ignoredException) { + } + } + return content; } public static byte[] read(final InputStream source, final int count) throws IOException {