All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.reactivex.core.streams.WriteStream Maven / Gradle / Ivy

The newest version!
/*
 * 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.reactivex.core.streams;

import io.vertx.reactivex.RxHelper;
import io.vertx.reactivex.ObservableHelper;
import io.vertx.reactivex.FlowableHelper;
import io.vertx.reactivex.impl.AsyncResultMaybe;
import io.vertx.reactivex.impl.AsyncResultSingle;
import io.vertx.reactivex.impl.AsyncResultCompletable;
import io.vertx.reactivex.WriteStreamObserver;
import io.vertx.reactivex.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;

/**
 *
 * Represents a stream of data that can be written to.
 * 

* Any class that implements this interface can be used by a {@link io.vertx.reactivex.core.streams.Pipe} to pipe data from a ReadStream * to it. * *

* NOTE: This class has been automatically generated from the {@link io.vertx.core.streams.WriteStream original} non RX-ified interface using Vert.x codegen. */ @RxGen(io.vertx.core.streams.WriteStream.class) public interface WriteStream extends io.vertx.reactivex.core.streams.StreamBase { io.vertx.core.streams.WriteStream getDelegate(); /** * 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.reactivex.core.streams.WriteStream exceptionHandler(io.vertx.core.Handler handler); /** * Write some data to the stream. * *

The data is usually 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.reactivex.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if * using a {@link io.vertx.reactivex.core.streams.Pipe}. * *

When the data is moved from the queue to the actual medium, the returned * will be completed with the write result, e.g the future is succeeded * when a server HTTP response buffer is written to the socket and failed if the remote * client has closed the socket while the data was still pending for write. * @param data the data to write * @return a future completed with the write result */ public io.vertx.core.Future write(T data); /** * Write some data to the stream. * *

The data is usually 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.reactivex.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if * using a {@link io.vertx.reactivex.core.streams.Pipe}. * *

When the data is moved from the queue to the actual medium, the returned * will be completed with the write result, e.g the future is succeeded * when a server HTTP response buffer is written to the socket and failed if the remote * client has closed the socket while the data was still pending for write. * @param data the data to write * @return a future completed with the write result */ public io.reactivex.Completable rxWrite(T data); /** * Ends the stream. *

* Once the stream has ended, it cannot be used any more. * @return a future completed with the result */ public io.vertx.core.Future end(); /** * Ends the stream. *

* Once the stream has ended, it cannot be used any more. * @return a future completed with the result */ public io.reactivex.Completable rxEnd(); /** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write * @return a future completed with the result */ public io.vertx.core.Future end(T data); /** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write * @return a future completed with the result */ public io.reactivex.Completable rxEnd(T data); /** * 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 * {@link io.vertx.reactivex.core.streams.Pipe} to provide flow control. *

* The value is defined by the implementation of the stream, e.g in bytes for a * {@link io.vertx.reactivex.core.net.NetSocket}, 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.reactivex.core.streams.WriteStream setWriteQueueMaxSize(int maxSize); /** * This will return true if there are more bytes in the write queue than the value set using {@link io.vertx.reactivex.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 {@link io.vertx.reactivex.core.streams.Pipe} 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. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.reactivex.core.streams.WriteStream drainHandler(io.vertx.core.Handler handler); WriteStreamObserver toObserver(); WriteStreamSubscriber toSubscriber(); public static WriteStream newInstance(io.vertx.core.streams.WriteStream arg) { return arg != null ? new WriteStreamImpl(arg) : null; } public static WriteStream newInstance(io.vertx.core.streams.WriteStream arg, TypeArg __typeArg_T) { return arg != null ? new WriteStreamImpl(arg, __typeArg_T) : null; } } class WriteStreamImpl implements WriteStream { private final io.vertx.core.streams.WriteStream delegate; public final TypeArg __typeArg_0; public WriteStreamImpl(io.vertx.core.streams.WriteStream delegate) { this.delegate = delegate; this.__typeArg_0 = TypeArg.unknown(); } public WriteStreamImpl(Object delegate, TypeArg typeArg_0) { this.delegate = (io.vertx.core.streams.WriteStream)delegate; this.__typeArg_0 = typeArg_0; } public io.vertx.core.streams.WriteStream getDelegate() { return delegate; } private WriteStreamObserver observer; private WriteStreamSubscriber subscriber; public synchronized WriteStreamObserver toObserver() { if (observer == null) { Function conv = (Function) __typeArg_0.unwrap; observer = RxHelper.toObserver(getDelegate(), conv); } return observer; } public synchronized WriteStreamSubscriber toSubscriber() { if (subscriber == null) { Function conv = (Function) __typeArg_0.unwrap; subscriber = RxHelper.toSubscriber(getDelegate(), conv); } return subscriber; } /** * 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.reactivex.core.streams.WriteStream exceptionHandler(io.vertx.core.Handler handler) { delegate.exceptionHandler(handler); return this; } /** * Write some data to the stream. * *

The data is usually 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.reactivex.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if * using a {@link io.vertx.reactivex.core.streams.Pipe}. * *

When the data is moved from the queue to the actual medium, the returned * will be completed with the write result, e.g the future is succeeded * when a server HTTP response buffer is written to the socket and failed if the remote * client has closed the socket while the data was still pending for write. * @param data the data to write * @return a future completed with the write result */ public io.vertx.core.Future write(T data) { io.vertx.core.Future ret = delegate.write(__typeArg_0.unwrap(data)).map(val -> val); return ret; } /** * Write some data to the stream. * *

The data is usually 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.reactivex.core.streams.WriteStream#writeQueueFull} method before writing. This is done automatically if * using a {@link io.vertx.reactivex.core.streams.Pipe}. * *

When the data is moved from the queue to the actual medium, the returned * will be completed with the write result, e.g the future is succeeded * when a server HTTP response buffer is written to the socket and failed if the remote * client has closed the socket while the data was still pending for write. * @param data the data to write * @return a future completed with the write result */ public io.reactivex.Completable rxWrite(T data) { return AsyncResultCompletable.toCompletable($handler -> { this.write(data).onComplete($handler); }); } /** * Ends the stream. *

* Once the stream has ended, it cannot be used any more. * @return a future completed with the result */ public io.vertx.core.Future end() { io.vertx.core.Future ret = delegate.end().map(val -> val); return ret; } /** * Ends the stream. *

* Once the stream has ended, it cannot be used any more. * @return a future completed with the result */ public io.reactivex.Completable rxEnd() { return AsyncResultCompletable.toCompletable($handler -> { this.end().onComplete($handler); }); } /** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write * @return a future completed with the result */ public io.vertx.core.Future end(T data) { io.vertx.core.Future ret = delegate.end(__typeArg_0.unwrap(data)).map(val -> val); return ret; } /** * Same as {@link io.vertx.reactivex.core.streams.WriteStream#end} but writes some data to the stream before ending. * @param data the data to write * @return a future completed with the result */ public io.reactivex.Completable rxEnd(T data) { return AsyncResultCompletable.toCompletable($handler -> { this.end(data).onComplete($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 * {@link io.vertx.reactivex.core.streams.Pipe} to provide flow control. *

* The value is defined by the implementation of the stream, e.g in bytes for a * {@link io.vertx.reactivex.core.net.NetSocket}, 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.reactivex.core.streams.WriteStream 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 {@link io.vertx.reactivex.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 {@link io.vertx.reactivex.core.streams.Pipe} 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. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public io.vertx.reactivex.core.streams.WriteStream drainHandler(io.vertx.core.Handler handler) { delegate.drainHandler(handler); return this; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy