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 6
6
import java .io .Closeable ;
7
7
import java .util .Iterator ;
8
8
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
10
11
* {@link ServerEvaluationCall#eval()}.
11
12
*/
12
13
public 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 ();
20
28
}
Original file line number Diff line number Diff line change @@ -3856,7 +3856,17 @@ private <U extends OkHttpResultIterator> U evalAndStreamResults(RequestLogger re
3856
3856
try {
3857
3857
MultipartReader reader = new MultipartReader (response .body ());
3858
3858
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
+ });
3860
3870
} catch (IOException e ) {
3861
3871
throw new MarkLogicIOException (e );
3862
3872
}
You can’t perform that action at this time.
0 commit comments