client.stream() return EventStream<T> (Iterable<T> and AutoCloseable). Use try (...) so the underlying HTTP connection closes when you exit the loop.
Filtered and sampled streams
Keep-alive and idle timeout
The X API sends a blank-line heartbeat about every 20 seconds. SetidleTimeout (e.g., Duration.ofSeconds(60)) and reconnectOnClose(true) on StreamConfig to recover silently stalled or closed connections, and onKeepAlive to observe heartbeats: