/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.rxjava.core.streams;

import java.util.Map;
import rx.Observable;
import rx.Single;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Represents a stream of data that can be written to.

Any class that implements this interface can be used by a Pipe to pipe data from a ReadStream to it.

NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.
/** * * Represents a stream of data that can be written to. * <p> * Any class that implements this interface can be used by a {@link io.vertx.rxjava.core.streams.Pipe} to pipe data from a <code>ReadStream</code> * to it. * * <p/> * NOTE: This class has been automatically generated from the {@link io.vertx.core.streams.WriteStream original} non RX-ified interface using Vert.x codegen. */
@io.vertx.lang.rx.RxGen(io.vertx.core.streams.WriteStream.class) public interface WriteStream<T> extends io.vertx.rxjava.core.streams.StreamBase { io.vertx.core.streams.WriteStream getDelegate();
Set an exception handler on the write stream.
Params:
  • handler – the exception handler
Returns:a reference to this, so the API can be used fluently
/** * Set an exception handler on the write stream. * @param handler the exception handler * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> exceptionHandler(Handler<Throwable> handler);
Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the writeQueueFull method before writing. This is done automatically if using a Pump.
Params:
  • data – the data to write
Returns:a reference to this, so the API can be used fluently
/** * Write some data to the stream. The data is put on an internal write queue, and the write actually happens * asynchronously. To avoid running out of memory by putting too much on the write queue, * check the {@link io.vertx.rxjava.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if using a {@link io.vertx.rxjava.core.streams.Pump}. * @param data the data to write * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> write(T data);
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler * @return */
public io.vertx.rxjava.core.streams.WriteStream<T> write(T data, Handler<AsyncResult<Void>> handler);
Ends the stream.

Once the stream has ended, it cannot be used any more.

/** * Ends the stream. * <p> * Once the stream has ended, it cannot be used any more. */
public void end();
Same as end but with an handler called when the operation completes
Params:
  • handler –
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @param handler */
public void end(Handler<AsyncResult<Void>> handler);
Same as end but writes some data to the stream before ending.
Params:
  • data – the data to write
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write */
public void end(T data);
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler */
public void end(T data, Handler<AsyncResult<Void>> handler);
Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pump to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc...
Params:
  • maxSize – the max size of the write stream
Returns:a reference to this, so the API can be used fluently
/** * Set the maximum size of the write queue to <code>maxSize</code>. You will still be able to write to the stream even * if there is more than <code>maxSize</code> items in the write queue. This is used as an indicator by classes such as * <code>Pump</code> to provide flow control. * <p/> * The value is defined by the implementation of the stream, e.g in bytes for a * {@link io.vertx.rxjava.core.net.NetSocket}, the number of {@link io.vertx.rxjava.core.eventbus.Message} for a * {@link io.vertx.rxjava.core.eventbus.MessageProducer}, etc... * @param maxSize the max size of the write stream * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> setWriteQueueMaxSize(int maxSize);
This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize
Returns:true if write queue is full
/** * This will return <code>true</code> if there are more bytes in the write queue than the value set using {@link io.vertx.rxjava.core.streams.WriteStream#setWriteQueueMaxSize} * @return true if write queue is full */
public boolean writeQueueFull();
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.
Params:
  • handler – the handler
Returns:a reference to this, so the API can be used fluently
/** * Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write * queue is ready to accept buffers again. See {@link io.vertx.rxjava.core.streams.Pump} for an example of this being used. * <p/> * The stream implementation defines when the drain handler, for example it could be when the queue size has been * reduced to <code>maxSize / 2</code>. * @param handler the handler * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> drainHandler(Handler<Void> handler); public static <T>WriteStream<T> newInstance(io.vertx.core.streams.WriteStream arg) { return arg != null ? new WriteStreamImpl<T>(arg) : null; } public static <T>WriteStream<T> newInstance(io.vertx.core.streams.WriteStream arg, io.vertx.lang.rx.TypeArg<T> __typeArg_T) { return arg != null ? new WriteStreamImpl<T>(arg, __typeArg_T) : null; } } class WriteStreamImpl<T> implements WriteStream<T> { private final io.vertx.core.streams.WriteStream<T> delegate; public final io.vertx.lang.rx.TypeArg<T> __typeArg_0; public WriteStreamImpl(io.vertx.core.streams.WriteStream delegate) { this.delegate = delegate; this.__typeArg_0 = io.vertx.lang.rx.TypeArg.unknown(); } public WriteStreamImpl(io.vertx.core.streams.WriteStream delegate, io.vertx.lang.rx.TypeArg<T> typeArg_0) { this.delegate = delegate; this.__typeArg_0 = typeArg_0; } public io.vertx.core.streams.WriteStream getDelegate() { return delegate; } private io.vertx.rx.java.WriteStreamSubscriber<T> subscriber; public synchronized io.vertx.rx.java.WriteStreamSubscriber<T> toSubscriber() { if (subscriber == null) { java.util.function.Function<T, T> conv = (java.util.function.Function<T, T>) __typeArg_0.unwrap; subscriber = io.vertx.rx.java.RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; }
Set an exception handler on the write stream.
Params:
  • handler – the exception handler
Returns:a reference to this, so the API can be used fluently
/** * Set an exception handler on the write stream. * @param handler the exception handler * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> exceptionHandler(Handler<Throwable> handler) { delegate.exceptionHandler(handler); return this; }
Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the WriteStream.writeQueueFull method before writing. This is done automatically if using a Pump.
Params:
  • data – the data to write
Returns:a reference to this, so the API can be used fluently
/** * Write some data to the stream. The data is put on an internal write queue, and the write actually happens * asynchronously. To avoid running out of memory by putting too much on the write queue, * check the {@link io.vertx.rxjava.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if using a {@link io.vertx.rxjava.core.streams.Pump}. * @param data the data to write * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> write(T data) { delegate.write(__typeArg_0.<T>unwrap(data)); return this; }
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler * @return */
public io.vertx.rxjava.core.streams.WriteStream<T> write(T data, Handler<AsyncResult<Void>> handler) { delegate.write(__typeArg_0.<T>unwrap(data), handler); return this; }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
Deprecated:use rxWrite instead
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return * @deprecated use {@link #rxWrite} instead */
@Deprecated() public Observable<Void> writeObservable(T data) { io.vertx.rx.java.ObservableFuture<Void> handler = io.vertx.rx.java.RxHelper.observableFuture(); write(data, handler.toHandler()); return handler; }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return */
public Single<Void> rxWrite(T data) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { write(data, fut); })); }
Ends the stream.

Once the stream has ended, it cannot be used any more.

/** * Ends the stream. * <p> * Once the stream has ended, it cannot be used any more. */
public void end() { delegate.end(); }
Same as WriteStream.end but with an handler called when the operation completes
Params:
  • handler –
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @param handler */
public void end(Handler<AsyncResult<Void>> handler) { delegate.end(handler); }
Same as WriteStream.end but with an handler called when the operation completes
Returns:
Deprecated:use rxEnd instead
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @return * @deprecated use {@link #rxEnd} instead */
@Deprecated() public Observable<Void> endObservable() { io.vertx.rx.java.ObservableFuture<Void> handler = io.vertx.rx.java.RxHelper.observableFuture(); end(handler.toHandler()); return handler; }
Same as WriteStream.end but with an handler called when the operation completes
Returns:
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but with an <code>handler</code> called when the operation completes * @return */
public Single<Void> rxEnd() { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(fut); })); }
Same as WriteStream.end but writes some data to the stream before ending.
Params:
  • data – the data to write
/** * Same as {@link io.vertx.rxjava.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write */
public void end(T data) { delegate.end(__typeArg_0.<T>unwrap(data)); }
Same as but with an handler called when the operation completes
Params:
  • data –
  • handler –
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @param handler */
public void end(T data, Handler<AsyncResult<Void>> handler) { delegate.end(__typeArg_0.<T>unwrap(data), handler); }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
Deprecated:use rxEnd instead
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return * @deprecated use {@link #rxEnd} instead */
@Deprecated() public Observable<Void> endObservable(T data) { io.vertx.rx.java.ObservableFuture<Void> handler = io.vertx.rx.java.RxHelper.observableFuture(); end(data, handler.toHandler()); return handler; }
Same as but with an handler called when the operation completes
Params:
  • data –
Returns:
/** * Same as but with an <code>handler</code> called when the operation completes * @param data * @return */
public Single<Void> rxEnd(T data) { return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut -> { end(data, fut); })); }
Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize items in the write queue. This is used as an indicator by classes such as Pump to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a NetSocket, the number of Message for a MessageProducer, etc...
Params:
  • maxSize – the max size of the write stream
Returns:a reference to this, so the API can be used fluently
/** * Set the maximum size of the write queue to <code>maxSize</code>. You will still be able to write to the stream even * if there is more than <code>maxSize</code> items in the write queue. This is used as an indicator by classes such as * <code>Pump</code> to provide flow control. * <p/> * The value is defined by the implementation of the stream, e.g in bytes for a * {@link io.vertx.rxjava.core.net.NetSocket}, the number of {@link io.vertx.rxjava.core.eventbus.Message} for a * {@link io.vertx.rxjava.core.eventbus.MessageProducer}, etc... * @param maxSize the max size of the write stream * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> setWriteQueueMaxSize(int maxSize) { delegate.setWriteQueueMaxSize(maxSize); return this; }
This will return true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize
Returns:true if write queue is full
/** * This will return <code>true</code> if there are more bytes in the write queue than the value set using {@link io.vertx.rxjava.core.streams.WriteStream#setWriteQueueMaxSize} * @return true if write queue is full */
public boolean writeQueueFull() { boolean ret = delegate.writeQueueFull(); return ret; }
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue is ready to accept buffers again. See Pump for an example of this being used.

The stream implementation defines when the drain handler, for example it could be when the queue size has been reduced to maxSize / 2.
Params:
  • handler – the handler
Returns:a reference to this, so the API can be used fluently
/** * Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write * queue is ready to accept buffers again. See {@link io.vertx.rxjava.core.streams.Pump} for an example of this being used. * <p/> * The stream implementation defines when the drain handler, for example it could be when the queue size has been * reduced to <code>maxSize / 2</code>. * @param handler the handler * @return a reference to this, so the API can be used fluently */
public io.vertx.rxjava.core.streams.WriteStream<T> drainHandler(Handler<Void> handler) { delegate.drainHandler(handler); return this; } }