api/metrics-api-jaxrs/src/main/java/org/hawkular/metrics/api/servlet/rx/ObservableServlet.java
public static Observable<Void> write(final Observable<byte[]> data, final ServletOutputStream out) {
        return Observable.create(new Observable.OnSubscribe<Void>() {
            @Override
            public void call(Subscriber<? super Void> subscriber) {
                Observable<Void> events = create(out).onBackpressureBuffer();
                Observable<Void> writeobs = Observable.zip(data, events, (b, aVoid) -> {
                    try {
                        out.write(b);
                    } catch (IOException ioe) {
                        Exceptions.propagate(ioe);
                    }
                    return null;
                });
                writeobs.subscribe(subscriber);
            }
        });
    }
public static Observable<Void> write(final Observable<byte[]> data, final ServletOutputStream out) {
        return Observable.create(new Observable.OnSubscribe<Void>() {
            @Override
            public void call(Subscriber<? super Void> subscriber) {
                Observable<Void> events = create(out).onBackpressureBuffer();
                Observable<Void> writeobs = Observable.zip(data, events, (b, aVoid) -> {
                    try {
                        out.write(b);
                    } catch (IOException ioe) {
                        Exceptions.propagate(ioe);
                    }
                    return null;
                });
                writeobs.subscribe(subscriber);
            }
        });
    }
public static Observable < Void > write ( final Observable < byte [ ] > data , final ServletOutputStream out ) { return Observable . create ( new Observable . OnSubscribe < Void > ( ) { @ Override public void call ( Subscriber < ? super Void > subscriber ) { Observable < Void > events = create ( out ) . onBackpressureBuffer ( ) ; Observable < Void > writeobs = Observable . zip ( data , events , ( b , aVoid ) -> { try { out . write ( b ) ; } catch ( IOException ioe ) { Exceptions . propagate ( ioe ) ; } return null ; } ) ; writeobs . subscribe ( subscriber ) ; } } ) ; }
Writes the given Observable data to ServletOutputStream.

<p>
This method uses Servlet 3.1 non-blocking API callback mechanisms. When the HTTP
request data becomes available to be read, the subscribed {@code Observer}'s
{@link Observer#onNext onNext} method is invoked. Similarly, when all data for the
HTTP request has been read, the subscribed {@code Observer}'s
{@link Observer#onCompleted onCompleted} method is invoked.

<p>
Before calling this method, a web application must put the corresponding HTTP request
into asynchronous mode.

@param data
@param out servlet output stream
@return
Writes the given Observable data to ServletOutputStream .