Top Description Methods
io.vertx.core.streams

public Interface WriteStream<T>

extends StreamBase
Known Direct Subinterfaces
io.vertx.core.file.AsyncFile, io.vertx.core.http.HttpClientRequest, io.vertx.core.http.HttpServerResponse, io.vertx.core.http.WebSocketBase, io.vertx.core.http.impl.HttpClientStream, io.vertx.core.net.NetSocket
Known Direct Implementers
io.vertx.core.datagram.impl.PacketWriteStreamImpl
Annotations
@VertxGen
concrete:false
Imports
io.vertx.codegen.annotations.Fluent, .Nullable, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, .Promise

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.

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public WriteStream<T>

Returns:

a reference to this, so the API can be used fluently
drainHandler
(@Nullable Handler<Void>
the handler
handler
)

Set a drain handler on the stream.

public default Future<Void>

Returns:

a future completed with the result
end
()

Ends the stream.

public void
end(Handler<AsyncResult<Void>> handler)

Same as end() but with an handler called when the operation completes

public default Future<Void>

Returns:

a future completed with the result
end
(T
the data to write
data
)

Same as end() but writes some data to the stream before ending.

public default void
end(T data, Handler<AsyncResult<Void>> handler)

Same as end(T) but with an handler called when the operation completes

public WriteStream<T>

Returns:

a reference to this, so the API can be used fluently
exceptionHandler
(@Nullable Handler<Throwable>
the exception handler
handler
)

Set an exception handler on the write stream.

public WriteStream<T>

Returns:

a reference to this, so the API can be used fluently
setWriteQueueMaxSize
(int
the max size of the write stream
maxSize
)

Set the maximum size of the write queue to maxSize.

public Future<Void>

Returns:

a future completed with the write result
write
(T
the data to write
data
)

Write some data to the stream.

public void
write(T data, Handler<AsyncResult<Void>> handler)

Same as write(T) but with an handler called when the operation completes

public boolean

Returns:

true if write queue is full
writeQueueFull
()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Inherited from io.vertx.core.streams.StreamBase:
exceptionHandler

Method Detail

drainHandlerback to summary
public WriteStream<T> drainHandler(@Nullable Handler<Void> handler)

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 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.

Parameters
handler:@Nullable Handler<Void>

the handler

Returns:WriteStream<T>

a reference to this, so the API can be used fluently

Annotations
@Fluent
endback to summary
public default Future<Void> end()

Ends the stream.

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

Returns:Future<Void>

a future completed with the result

endback to summary
public void end(Handler<AsyncResult<Void>> handler)

Same as end() but with an handler called when the operation completes

endback to summary
public default Future<Void> end(T data)

Same as end() but writes some data to the stream before ending.

Implementation Specification

The default default implementation calls sequentially write(Object) then end()

API Note

Implementations might want to perform a single operation

Parameters
data:T

the data to write

Returns:Future<Void>

a future completed with the result

endback to summary
public default void end(T data, Handler<AsyncResult<Void>> handler)

Same as end(T) but with an handler called when the operation completes

exceptionHandlerback to summary
public WriteStream<T> exceptionHandler(@Nullable Handler<Throwable> handler)

Set an exception handler on the write stream.

Parameters
handler:@Nullable Handler<Throwable>

the exception handler

Returns:WriteStream<T>

a reference to this, so the API can be used fluently

Annotations
@Override
setWriteQueueMaxSizeback to summary
public WriteStream<T> setWriteQueueMaxSize(int maxSize)

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 Pipe to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a io.vertx.core.net.NetSocket, etc...

Parameters
maxSize:int

the max size of the write stream

Returns:WriteStream<T>

a reference to this, so the API can be used fluently

Annotations
@Fluent
writeback to summary
public Future<Void> 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 writeQueueFull method before writing. This is done automatically if using a Pipe.

When the data is moved from the queue to the actual medium, the returned Future 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.

Parameters
data:T

the data to write

Returns:Future<Void>

a future completed with the write result

writeback to summary
public void write(T data, Handler<AsyncResult<Void>> handler)

Same as write(T) but with an handler called when the operation completes

writeQueueFullback to summary
public boolean writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

Returns:boolean

true if write queue is full