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\u003eThis webpage provides documentation for the \u003ccode\u003eServerStream\u003c/code\u003e class in the Google API Client Libraries for Java, offering various versions of the class, ranging from 2.63.1 (latest) down to 2.7.1.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eServerStream\u003c/code\u003e class serves as a blocking, iterable wrapper around server stream responses, allowing for consumption of responses via an iterator that pulls responses from upstream asynchronously.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eServerStream\u003c/code\u003e can only be consumed once and must either be fully consumed or canceled, as neither the class nor its returned iterator is thread-safe, providing methods for canceling \u003ccode\u003e(cancel())\u003c/code\u003e or checking for non-blocking readiness \u003ccode\u003e(isReceiveReady())\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe class provides a \u003ccode\u003estream()\u003c/code\u003e method for returning a sequential \u003ccode\u003eStream\u003c/code\u003e with server responses as the source, as well as a \u003ccode\u003eiterator()\u003c/code\u003e method for returning the object's iterator.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eServerStream\u003c/code\u003e class inherits several members from \u003ccode\u003ejava.lang.Object\u003c/code\u003e such as \u003ccode\u003eclone()\u003c/code\u003e, \u003ccode\u003eequals(Object)\u003c/code\u003e, \u003ccode\u003efinalize()\u003c/code\u003e, \u003ccode\u003egetClass()\u003c/code\u003e, \u003ccode\u003ehashCode()\u003c/code\u003e, \u003ccode\u003enotify()\u003c/code\u003e, \u003ccode\u003enotifyAll()\u003c/code\u003e, \u003ccode\u003etoString()\u003c/code\u003e, \u003ccode\u003ewait()\u003c/code\u003e, \u003ccode\u003ewait(long)\u003c/code\u003e, and \u003ccode\u003ewait(long, int)\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,[]]