public final class Channels extends Object
Modifier and Type | Method and Description |
---|---|
static <C extends ConnectedChannel,A extends AcceptingChannel<C>> |
acceptBlocking(A channel)
Simple utility method to execute a blocking accept on an accepting channel.
|
static <C extends ConnectedChannel,A extends AcceptingChannel<C>> |
acceptBlocking(A channel,
long time,
TimeUnit unit)
Simple utility method to execute a blocking accept on an accepting channel, with a timeout.
|
static long |
drain(FileChannel channel,
long position,
long count)
Attempt to drain the given number of bytes from the file channel.
|
static long |
drain(ReadableByteChannel channel,
long count)
Attempt to drain the given number of bytes from the readable byte channel.
|
static long |
drain(StreamSourceChannel channel,
long count)
Attempt to drain the given number of bytes from the stream source channel.
|
static void |
flushBlocking(SuspendableWriteChannel channel)
Simple utility method to execute a blocking flush on a writable channel.
|
static boolean |
flushBlocking(SuspendableWriteChannel channel,
long time,
TimeUnit unit)
Simple utility method to execute a blocking flush on a writable channel.
|
static boolean |
getOption(Configurable configurable,
Option<Boolean> option,
boolean defaultValue)
Get an option value from a configurable target.
|
static int |
getOption(Configurable configurable,
Option<Integer> option,
int defaultValue)
Get an option value from a configurable target.
|
static long |
getOption(Configurable configurable,
Option<Long> option,
long defaultValue)
Get an option value from a configurable target.
|
static <T> T |
getOption(Configurable configurable,
Option<T> option,
T defaultValue)
Get an option value from a configurable target.
|
static <C extends ReadableByteChannel & SuspendableReadChannel> |
readBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking read on a readable byte channel.
|
static <C extends ScatteringByteChannel & SuspendableReadChannel> |
readBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking read on a scattering byte channel.
|
static <C extends ScatteringByteChannel & SuspendableReadChannel> |
readBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len,
long time,
TimeUnit unit)
Simple utility method to execute a blocking read on a scattering byte channel with a timeout.
|
static <C extends ReadableByteChannel & SuspendableReadChannel> |
readBlocking(C channel,
ByteBuffer buffer,
long time,
TimeUnit unit)
Simple utility method to execute a blocking read on a readable byte channel with a timeout.
|
static <C extends ReadableMessageChannel> |
receiveBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking receive on a readable message channel.
|
static <C extends ReadableMessageChannel> |
receiveBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking receive on a readable message channel.
|
static <C extends ReadableMessageChannel> |
receiveBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len,
long time,
TimeUnit unit)
Simple utility method to execute a blocking receive on a readable message channel with a timeout.
|
static <C extends ReadableMessageChannel> |
receiveBlocking(C channel,
ByteBuffer buffer,
long time,
TimeUnit unit)
Simple utility method to execute a blocking receive on a readable message channel with a timeout.
|
static void |
resumeReadsAsync(SuspendableReadChannel channel)
Resume reads asynchronously.
|
static void |
resumeWritesAsync(SuspendableWriteChannel channel)
Resume writes asynchronously.
|
static <C extends WritableMessageChannel> |
sendBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking send on a message channel.
|
static <C extends WritableMessageChannel> |
sendBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking gathering send on a message channel.
|
static <C extends WritableMessageChannel> |
sendBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len,
long time,
TimeUnit unit)
Simple utility method to execute a blocking gathering send on a message channel with a timeout.
|
static <C extends WritableMessageChannel> |
sendBlocking(C channel,
ByteBuffer buffer,
long time,
TimeUnit unit)
Simple utility method to execute a blocking send on a message channel with a timeout.
|
static <T extends AcceptingChannel<?>> |
setAcceptListener(T channel,
ChannelListener<? super T> listener)
Set the accept listener for a channel (type-safe).
|
static <T extends CloseableChannel> |
setCloseListener(T channel,
ChannelListener<? super T> listener)
Set the close listener for a channel (type-safe).
|
static <T extends SuspendableReadChannel> |
setReadListener(T channel,
ChannelListener<? super T> listener)
Set the read listener for a channel (type-safe).
|
static <T extends SuspendableWriteChannel> |
setWriteListener(T channel,
ChannelListener<? super T> listener)
Set the write listener for a channel (type-safe).
|
static void |
shutdownWritesBlocking(SuspendableWriteChannel channel)
Simple utility method to execute a blocking write shutdown on a writable channel.
|
static boolean |
shutdownWritesBlocking(SuspendableWriteChannel channel,
long time,
TimeUnit unit)
Simple utility method to execute a blocking write shutdown on a writable channel.
|
static void |
transferBlocking(FileChannel destination,
StreamSourceChannel source,
long startPosition,
long count)
Transfer bytes between two channels efficiently, blocking if necessary.
|
static void |
transferBlocking(StreamSinkChannel destination,
FileChannel source,
long startPosition,
long count)
Transfer bytes between two channels efficiently, blocking if necessary.
|
static long |
transferBlocking(StreamSinkChannel destination,
StreamSourceChannel source,
ByteBuffer throughBuffer,
long count)
Transfer bytes between two channels efficiently, blocking if necessary.
|
static <T extends Channel> |
unwrap(Class<T> targetType,
Channel channel)
Unwrap a nested channel type.
|
static ByteChannel |
wrapByteChannel(ByteChannel original)
Create a wrapper for a byte channel which does not expose other methods.
|
static <C extends WritableByteChannel & SuspendableWriteChannel> |
writeBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking write on a byte channel.
|
static <C extends GatheringByteChannel & SuspendableWriteChannel> |
writeBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking write on a gathering byte channel.
|
static <C extends GatheringByteChannel & SuspendableWriteChannel> |
writeBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len,
long time,
TimeUnit unit)
Simple utility method to execute a blocking write on a gathering byte channel with a timeout.
|
static <C extends WritableByteChannel & SuspendableWriteChannel> |
writeBlocking(C channel,
ByteBuffer buffer,
long time,
TimeUnit unit)
Simple utility method to execute a blocking write on a byte channel with a timeout.
|
static int |
writeFinalBasic(StreamSinkChannel channel,
ByteBuffer src)
Writes out the data in the buffer to the channel.
|
static long |
writeFinalBasic(StreamSinkChannel channel,
ByteBuffer[] srcs,
int offset,
int length)
Writes out the data in the buffer to the channel.
|
public static void flushBlocking(SuspendableWriteChannel channel) throws IOException
channel
- the writable channelIOException
- if an I/O exception occurspublic static boolean flushBlocking(SuspendableWriteChannel channel, long time, TimeUnit unit) throws IOException
channel
- the writable channeltime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static void shutdownWritesBlocking(SuspendableWriteChannel channel) throws IOException
channel
- the writable channelIOException
- if an I/O exception occurspublic static boolean shutdownWritesBlocking(SuspendableWriteChannel channel, long time, TimeUnit unit) throws IOException
channel
- the writable channeltime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends WritableByteChannel & SuspendableWriteChannel> int writeBlocking(C channel, ByteBuffer buffer) throws IOException
flushBlocking(SuspendableWriteChannel)
method should be called after all writes are complete.C
- the channel typechannel
- the channel to write onbuffer
- the data to writeIOException
- if an I/O exception occurspublic static <C extends WritableByteChannel & SuspendableWriteChannel> int writeBlocking(C channel, ByteBuffer buffer, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to write onbuffer
- the data to writetime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends GatheringByteChannel & SuspendableWriteChannel> long writeBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException
C
- the channel typechannel
- the channel to write onbuffers
- the data to writeoffs
- the index of the first buffer to writelen
- the number of buffers to writeIOException
- if an I/O exception occurspublic static <C extends GatheringByteChannel & SuspendableWriteChannel> long writeBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to write onbuffers
- the data to writeoffs
- the index of the first buffer to writelen
- the number of buffers to writetime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends WritableMessageChannel> void sendBlocking(C channel, ByteBuffer buffer) throws IOException
C
- the channel typechannel
- the channel to write onbuffer
- the data to writeIOException
- if an I/O exception occurspublic static <C extends WritableMessageChannel> boolean sendBlocking(C channel, ByteBuffer buffer, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to write onbuffer
- the data to writetime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends WritableMessageChannel> void sendBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException
C
- the channel typechannel
- the channel to write onbuffers
- the data to writeoffs
- the index of the first buffer to writelen
- the number of buffers to writeIOException
- if an I/O exception occurspublic static <C extends WritableMessageChannel> boolean sendBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to write onbuffers
- the data to writeoffs
- the index of the first buffer to writelen
- the number of buffers to writetime
- the amount of time to waitunit
- the unit of time to waittrue
if the message was written before the timeoutIOException
- if an I/O exception occurspublic static <C extends ReadableByteChannel & SuspendableReadChannel> int readBlocking(C channel, ByteBuffer buffer) throws IOException
C
- the channel typechannel
- the channel to read frombuffer
- the buffer into which bytes are to be transferredIOException
- if an I/O exception occurspublic static <C extends ReadableByteChannel & SuspendableReadChannel> int readBlocking(C channel, ByteBuffer buffer, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to read frombuffer
- the buffer into which bytes are to be transferredtime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends ScatteringByteChannel & SuspendableReadChannel> long readBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException
C
- the channel typechannel
- the channel to read frombuffers
- the buffers into which bytes are to be transferredoffs
- the first buffer to uselen
- the number of buffers to useIOException
- if an I/O exception occurspublic static <C extends ScatteringByteChannel & SuspendableReadChannel> long readBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to read frombuffers
- the buffers into which bytes are to be transferredoffs
- the first buffer to uselen
- the number of buffers to usetime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends ReadableMessageChannel> int receiveBlocking(C channel, ByteBuffer buffer) throws IOException
C
- the channel typechannel
- the channel to read frombuffer
- the buffer into which bytes are to be transferredIOException
- if an I/O exception occurspublic static <C extends ReadableMessageChannel> int receiveBlocking(C channel, ByteBuffer buffer, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to read frombuffer
- the buffer into which bytes are to be transferredtime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends ReadableMessageChannel> long receiveBlocking(C channel, ByteBuffer[] buffers, int offs, int len) throws IOException
C
- the channel typechannel
- the channel to read frombuffers
- the buffers into which bytes are to be transferredoffs
- the first buffer to uselen
- the number of buffers to useIOException
- if an I/O exception occurspublic static <C extends ReadableMessageChannel> long receiveBlocking(C channel, ByteBuffer[] buffers, int offs, int len, long time, TimeUnit unit) throws IOException
C
- the channel typechannel
- the channel to read frombuffers
- the buffers into which bytes are to be transferredoffs
- the first buffer to uselen
- the number of buffers to usetime
- the amount of time to waitunit
- the unit of time to waitIOException
- if an I/O exception occurspublic static <C extends ConnectedChannel,A extends AcceptingChannel<C>> C acceptBlocking(A channel) throws IOException
C
- the connection channel typeA
- the accepting channel typechannel
- the accepting channelIOException
- if an I/O error occurspublic static <C extends ConnectedChannel,A extends AcceptingChannel<C>> C acceptBlocking(A channel, long time, TimeUnit unit) throws IOException
C
- the connection channel typeA
- the accepting channel typechannel
- the accepting channeltime
- the amount of time to waitunit
- the unit of time to waitnull
if the timeout occurred before a connection was acceptedIOException
- if an I/O error occurspublic static void transferBlocking(StreamSinkChannel destination, FileChannel source, long startPosition, long count) throws IOException
destination
- the destination channelsource
- the source file channelstartPosition
- the start position in the source filecount
- the number of bytes to transferIOException
- if an I/O error occurspublic static void transferBlocking(FileChannel destination, StreamSourceChannel source, long startPosition, long count) throws IOException
destination
- the destination file channelsource
- the source channelstartPosition
- the start position in the destination filecount
- the number of bytes to transferIOException
- if an I/O error occurspublic static long transferBlocking(StreamSinkChannel destination, StreamSourceChannel source, ByteBuffer throughBuffer, long count) throws IOException
destination
- the destination channelsource
- the source channelthroughBuffer
- the buffer to transfer through,count
- the number of bytes to transfercount
if EOF was reached)IOException
- if the transfer failspublic static <T extends CloseableChannel> void setCloseListener(T channel, ChannelListener<? super T> listener)
T
- the channel typechannel
- the channellistener
- the listener to setpublic static <T extends AcceptingChannel<?>> void setAcceptListener(T channel, ChannelListener<? super T> listener)
T
- the channel typechannel
- the channellistener
- the listener to setpublic static <T extends SuspendableReadChannel> void setReadListener(T channel, ChannelListener<? super T> listener)
T
- the channel typechannel
- the channellistener
- the listener to setpublic static <T extends SuspendableWriteChannel> void setWriteListener(T channel, ChannelListener<? super T> listener)
T
- the channel typechannel
- the channellistener
- the listener to setpublic static ByteChannel wrapByteChannel(ByteChannel original)
original
- the originalpublic static <T> T getOption(Configurable configurable, Option<T> option, T defaultValue)
T
- the option value typeconfigurable
- the configurable targetoption
- the optiondefaultValue
- the default valuepublic static boolean getOption(Configurable configurable, Option<Boolean> option, boolean defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default valuepublic static int getOption(Configurable configurable, Option<Integer> option, int defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default valuepublic static long getOption(Configurable configurable, Option<Long> option, long defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default valuepublic static <T extends Channel> T unwrap(Class<T> targetType, Channel channel)
null
is returned.T
- the type to unwraptargetType
- the class to unwrapchannel
- the channelnull
if the given type is not wrappedWrappedChannel
public static long drain(StreamSourceChannel channel, long count) throws IOException
channel
- the channel to draincount
- the number of bytesIOException
- if an error occurspublic static long drain(ReadableByteChannel channel, long count) throws IOException
channel
- the channel to draincount
- the number of bytesIOException
- if an error occurspublic static long drain(FileChannel channel, long position, long count) throws IOException
channel
- the channel to drainposition
- the position to drain fromcount
- the number of bytesIOException
- if an error occurspublic static void resumeReadsAsync(SuspendableReadChannel channel)
channel
- the channel to resumepublic static void resumeWritesAsync(SuspendableWriteChannel channel)
channel
- the channel to resumepublic static int writeFinalBasic(StreamSinkChannel channel, ByteBuffer src) throws IOException
channel
- The channelsrc
- The bufferIOException
public static long writeFinalBasic(StreamSinkChannel channel, ByteBuffer[] srcs, int offset, int length) throws IOException
channel
- The channelsrcs
- The buffersoffset
- The offset into the srcs arraylength
- The number buffers to writeIOException
Copyright © 2021 JBoss by Red Hat. All rights reserved.