|
XNIO API 3.0.4.GA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.xnio.channels.Channels
public final class Channels
A utility class containing static methods to support channel usage.
Method Summary | ||
---|---|---|
static
|
acceptBlocking(A channel)
Simple utility method to execute a blocking accept on an accepting channel. |
|
static
|
acceptBlocking(A channel,
long time,
TimeUnit unit)
Simple utility method to execute a blocking accept on an accepting channel, with a timeout. |
|
static void |
flushBlocking(SuspendableWriteChannel channel)
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
|
getOption(Configurable configurable,
Option<T> option,
T defaultValue)
Get an option value from a configurable target. |
|
static
|
readBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking read on a readable byte channel. |
|
static
|
readBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking read on a scattering byte channel. |
|
static
|
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
|
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
|
receiveBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking receive on a readable message channel. |
|
static
|
receiveBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking receive on a readable message channel. |
|
static
|
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
|
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
|
sendBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking send on a message channel. |
|
static
|
sendBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking gathering send on a message channel. |
|
static
|
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
|
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
|
setAcceptListener(T channel,
ChannelListener<? super T> listener)
Set the accept listener for a channel (type-safe). |
|
static
|
setCloseListener(T channel,
ChannelListener<? super T> listener)
Set the close listener for a channel (type-safe). |
|
static
|
setReadListener(T channel,
ChannelListener<? super T> listener)
Set the read listener for a channel (type-safe). |
|
static
|
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 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
|
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
|
writeBlocking(C channel,
ByteBuffer buffer)
Simple utility method to execute a blocking write on a byte channel. |
|
static
|
writeBlocking(C channel,
ByteBuffer[] buffers,
int offs,
int len)
Simple utility method to execute a blocking write on a gathering byte channel. |
|
static
|
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
|
writeBlocking(C channel,
ByteBuffer buffer,
long time,
TimeUnit unit)
Simple utility method to execute a blocking write on a byte channel with a timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void flushBlocking(SuspendableWriteChannel channel) throws IOException
channel
- the writable channel
IOException
- if an I/O exception occurspublic static void shutdownWritesBlocking(SuspendableWriteChannel channel) throws IOException
channel
- the writable channel
IOException
- 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 write
IOException
- 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 wait
IOException
- 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 write
IOException
- 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 wait
IOException
- 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 write
IOException
- 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 wait
IOException
- 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 write
IOException
- 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 wait
true
if the message was written before the timeout
IOException
- 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 transferred
IOException
- 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 wait
IOException
- 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 use
IOException
- 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 wait
IOException
- 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 transferred
IOException
- 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 wait
IOException
- 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 use
IOException
- 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 wait
IOException
- 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 channel
IOException
- 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 wait
null
if the timeout occurred before a connection was accepted
IOException
- 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 transfer
IOException
- 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 transfer
IOException
- if an I/O error occurspublic 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 original
public static <T> T getOption(Configurable configurable, Option<T> option, T defaultValue)
T
- the option value typeconfigurable
- the configurable targetoption
- the optiondefaultValue
- the default value
public static boolean getOption(Configurable configurable, Option<Boolean> option, boolean defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default value
public static int getOption(Configurable configurable, Option<Integer> option, int defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default value
public static long getOption(Configurable configurable, Option<Long> option, long defaultValue)
configurable
- the configurable targetoption
- the optiondefaultValue
- the default value
public static <T extends Channel> T unwrap(Class<T> targetType, Channel channel)
null
is returned.
T
- the type to unwraptargetType
- the class to unwrapchannel
- the channel
null
if the given type is not wrappedWrappedChannel
|
XNIO API 3.0.4.GA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |