File tree Expand file tree Collapse file tree 2 files changed +27
-9
lines changed
marklogic-client-api/src/main/java/com/marklogic/client Expand file tree Collapse file tree 2 files changed +27
-9
lines changed Original file line number Diff line number Diff line change 66import java .io .Closeable ;
77import java .util .Iterator ;
88
9- /** An Iterator to walk through all results returned from calls to
9+ /**
10+ * An Iterator to walk through all results returned from calls to
1011 * {@link ServerEvaluationCall#eval()}.
1112 */
1213public interface EvalResultIterator extends Iterable <EvalResult >, Iterator <EvalResult >, Closeable {
13- @ Override
14- Iterator <EvalResult > iterator ();
15- @ Override
16- boolean hasNext ();
17- @ Override
18- EvalResult next ();
19- void close ();
14+ @ Override
15+ Iterator <EvalResult > iterator ();
16+
17+ @ Override
18+ boolean hasNext ();
19+
20+ @ Override
21+ EvalResult next ();
22+
23+ /**
24+ * As of 7.1.0, this must be called to ensure that the response is closed, as results are now
25+ * streamed from MarkLogic instead of being read entirely into memory first.
26+ */
27+ void close ();
2028}
Original file line number Diff line number Diff line change @@ -3856,7 +3856,17 @@ private <U extends OkHttpResultIterator> U evalAndStreamResults(RequestLogger re
38563856 try {
38573857 MultipartReader reader = new MultipartReader (response .body ());
38583858 PartIterator partIterator = new PartIterator (reader );
3859- return (U ) new DefaultOkHttpResultIterator (reqlog , partIterator , response );
3859+ return (U ) new DefaultOkHttpResultIterator (reqlog , partIterator , () -> {
3860+ // Looking at OkHttp source code, it does not appear necessary to call close on the reader; it appears
3861+ // sufficient to only call it on the response. But doing both in case this behavior changes in a future
3862+ // OkHttp release.
3863+ try {
3864+ reader .close ();
3865+ } catch (IOException e ) {
3866+ // Ignore, the next call should close everything properly.
3867+ }
3868+ response .close ();
3869+ });
38603870 } catch (IOException e ) {
38613871 throw new MarkLogicIOException (e );
38623872 }
You can’t perform that action at this time.
0 commit comments