From 17c7a85f189c9ee2f1e83eba221fff4b6341df53 Mon Sep 17 00:00:00 2001 From: luccioman Date: Wed, 21 Feb 2018 08:38:35 +0100 Subject: [PATCH] Make StreamResponse usable in Java try-with-resources statements --- source/net/yacy/crawler/retrieval/StreamResponse.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/source/net/yacy/crawler/retrieval/StreamResponse.java b/source/net/yacy/crawler/retrieval/StreamResponse.java index d52614e4f..d8a1e9267 100644 --- a/source/net/yacy/crawler/retrieval/StreamResponse.java +++ b/source/net/yacy/crawler/retrieval/StreamResponse.java @@ -22,6 +22,7 @@ package net.yacy.crawler.retrieval; +import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; @@ -34,7 +35,7 @@ import net.yacy.document.TextParser; /** * A crawler load response, holding content as a stream. */ -public class StreamResponse { +public class StreamResponse implements Closeable { /** Logger */ private final static ConcurrentLog log = new ConcurrentLog(StreamResponse.class.getSimpleName()); @@ -79,6 +80,13 @@ public class StreamResponse { public Response getResponse() { return this.response; } + + @Override + public void close() throws IOException { + if(this.contentStream != null) { + this.contentStream.close(); + } + } /** * Parse and close the content stream and return the parsed documents when