A blocking Iterable-style wrapper around server stream responses.
This class asynchronously pulls responses from upstream via StreamController#request(int) and exposes them via its Iterator. The implementation is back
pressure aware and uses a constant buffer of 1 item.
Please note that the stream can only be consumed once and must either be fully consumed or be
canceled.
Neither this class nor the iterator it returns is thread-safe.
Example usage:
ServerStream<Item>stream=...;for(Itemitem:stream){System.out.println(item.id());// Allow for early terminationif(item.id().equals("needle")){// Cancelling the stream will cause hasNext() to return false on the next iteration,// naturally breaking the loop.stream.cancel();}}
Cleanly cancels a partially consumed stream. The associated iterator will return false for the
hasNext() in the next iteration. This maintains the contract that an observed true from
hasNext() will yield an item in next(), but afterwards will return false.
isReceiveReady()
publicbooleanisReceiveReady()
Returns true if the next call to the iterator's hasNext() or next() is guaranteed to be
nonblocking.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-15 UTC."],[[["\u003cp\u003eThe webpage provides documentation for the \u003ccode\u003eServerStream\u003c/code\u003e class in the Google API Client Libraries for Java, showcasing versions ranging from 2.7.1 to 2.63.1, with 2.63.1 being the latest.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eServerStream\u003c/code\u003e is a class that provides a blocking, Iterable-style wrapper for consuming server stream responses, and it asynchronously fetches data from upstream sources.\u003c/p\u003e\n"],["\u003cp\u003eThe stream can only be consumed once, requiring either full consumption or explicit cancellation, and neither the \u003ccode\u003eServerStream\u003c/code\u003e class nor its iterator is thread-safe.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eServerStream\u003c/code\u003e class includes methods like \u003ccode\u003ecancel()\u003c/code\u003e to terminate a stream early and \u003ccode\u003eisReceiveReady()\u003c/code\u003e to determine if the iterator's next operation will be non-blocking.\u003c/p\u003e\n"],["\u003cp\u003eThe class implements \u003ccode\u003eIterable<V>\u003c/code\u003e and inherits members from \u003ccode\u003eObject\u003c/code\u003e, including methods like \u003ccode\u003eequals\u003c/code\u003e, \u003ccode\u003ehashCode\u003c/code\u003e, and \u003ccode\u003etoString\u003c/code\u003e, while its iterator is retrieved via the \u003ccode\u003eiterator()\u003c/code\u003e method.\u003c/p\u003e\n"]]],[],null,[]]