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; package net.yacy.crawler.retrieval;
import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -34,7 +35,7 @@ import net.yacy.document.TextParser;
/** /**
* A crawler load response, holding content as a stream. * A crawler load response, holding content as a stream.
*/ */
public class StreamResponse { public class StreamResponse implements Closeable {
/** Logger */ /** Logger */
private final static ConcurrentLog log = new ConcurrentLog(StreamResponse.class.getSimpleName()); private final static ConcurrentLog log = new ConcurrentLog(StreamResponse.class.getSimpleName());
@ -80,6 +81,13 @@ public class StreamResponse {
return this.response; 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 * Parse and close the content stream and return the parsed documents when
* possible * possible

Loading…
Cancel
Save