Source:
public void submitAndIterate(final ResultStream.ForEachDoc f) throws LightblueException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Calling service (streaming): {}", req.toString()); } InputStream stream = httpTransport.executeRequestGetStream(req, configuration.getDataServiceURI()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Response received from service, streaming"); } if(stream!=null) { try { StreamJsonParser streamParser=new StreamJsonParser(stream,mapper) { @Override public boolean documentCompleted(ObjectNode n) { JsonNode status=n.get("status"); if(status!=null) { ResultStream.ResponseHeader header=ResultStream.ResponseHeader.fromJson(n); f.processResponseHeader(header); } JsonNode processed=n.get("processed"); if(processed instanceof ArrayNode) { List<ResultMetadata> lrmd=new ArrayList<ResultMetadata>(); JsonNode rmd=n.get("resultMetadata"); if(rmd instanceof ArrayNode) { for(Iterator<JsonNode> itr=rmd.elements();itr.hasNext();) { lrmd.add(ResultMetadata.fromJson((ObjectNode)itr.next())); } } int k=0; for(Iterator<JsonNode> itr=processed.elements();itr.hasNext();k++) { JsonNode docNode=itr.next(); ResultMetadata md; if(lrmd.size()>k) { md=lrmd.get(k); } else { md=null; } ResultStream.StreamDoc doc=new ResultStream.StreamDoc(); doc.doc=(ObjectNode)docNode; doc.resultMetadata=md; doc.lastDoc=!itr.hasNext(); if(!f.processDocument(doc)) return false; } } else if(processed instanceof ObjectNode) { ResultStream.StreamDoc doc=ResultStream.StreamDoc.fromJson(n); if(!f.processDocument(doc)) return false; } return true; } }; streamParser.parse(); } catch (IOException e) { throw new LightblueException(e); } finally { try { stream.close(); } catch (Exception e) } } }

Target:
public void submitAndIterate(final ResultStream.ForEachDoc f) throws LightblueException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Calling service (streaming): {}", req.toString()); } InputStream stream = httpTransport.executeRequestGetStream(req, configuration.getDataServiceURI()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Response received from service, streaming"); } if(stream!=null) { try { StreamJsonParser streamParser=new StreamJsonParser(stream,mapper) { @Override public boolean documentCompleted(ObjectNode n) { JsonNode status=n.get("status"); if(status!=null) { ResultStream.ResponseHeader header=ResultStream.ResponseHeader.fromJson(n); f.processResponseHeader(header); } JsonNode processed=n.get("processed"); if(processed instanceof ArrayNode) { LOGGER.debug("Results are not being streamed, retrieving all results"); List<ResultMetadata> lrmd=new ArrayList<ResultMetadata>(); JsonNode rmd=n.get("resultMetadata"); if(rmd instanceof ArrayNode) { for(Iterator<JsonNode> itr=rmd.elements();itr.hasNext();) { lrmd.add(ResultMetadata.fromJson((ObjectNode)itr.next())); } } int k=0; for(Iterator<JsonNode> itr=processed.elements();itr.hasNext();k++) { JsonNode docNode=itr.next(); ResultMetadata md; if(lrmd.size()>k) { md=lrmd.get(k); } else { md=null; } ResultStream.StreamDoc doc=new ResultStream.StreamDoc(); doc.doc=(ObjectNode)docNode; doc.resultMetadata=md; doc.lastDoc=!itr.hasNext(); if(!f.processDocument(doc)) return false; } } else if(processed instanceof ObjectNode) { LOGGER.debug("Retrieved one document from stream"); ResultStream.StreamDoc doc=ResultStream.StreamDoc.fromJson(n); if(!f.processDocument(doc)) { LOGGER.debug("Stream processing cancelled"); return false; } } return true; } }; streamParser.parse(); } catch (IOException e) { throw new LightblueException(e); } finally { try { stream.close(); } catch (Exception e) } } }