Make StreamResponse usable in Java try-with-resources statements

pull/167/head
luccioman 7 years ago
parent 348d07a999
commit 17c7a85f18

@ -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

Loading…
Cancel
Save