Top Description Fields Constructors Methods
org.xnio.channels

public final Class Channels

extends Object
Class Inheritance
Imports
java.io.FileNotFoundException, .FileOutputStream, .IOError, .InterruptedIOException, .IOException, java.nio.channels.Channel, .FileChannel, .WritableByteChannel, .GatheringByteChannel, .ReadableByteChannel, .ScatteringByteChannel, java.security.AccessController, .PrivilegedAction, java.util.Locale, org.xnio.Buffers, .ChannelListener, .Option, .XnioIoThread, java.nio.ByteBuffer, java.util.concurrent.TimeUnit

A utility class containing static methods to support channel usage.

Field Summary

Modifier and TypeField and Description
private static final ByteBuffer
private static final FileChannel

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
the connection channel type
C extends ConnectedChannel
,
the accepting channel type
A extends AcceptingChannel<C>
>
C

Returns:

the accepted channel
acceptBlocking
(A
the accepting channel
channel
)

Simple utility method to execute a blocking accept on an accepting channel.

public static <
the connection channel type
C extends ConnectedChannel
,
the accepting channel type
A extends AcceptingChannel<C>
>
C

Returns:

the accepted channel, or null if the timeout occurred before a connection was accepted
acceptBlocking
(A
the accepting channel
channel
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking accept on an accepting channel, with a timeout.

public static long

Returns:

the number of bytes drained, 0 if reading the channel would block, or -1 if the EOF was reached
drain
(StreamSourceChannel
the channel to drain
channel
,
long
the number of bytes
count
)

Attempt to drain the given number of bytes from the stream source channel.

public static long

Returns:

the number of bytes drained, 0 if reading the channel would block, or -1 if the EOF was reached
drain
(ReadableByteChannel
the channel to drain
channel
,
long
the number of bytes
count
)

Attempt to drain the given number of bytes from the readable byte channel.

public static long

Returns:

the number of bytes drained, 0 if reading the channel would block, or -1 if the EOF was reached
drain
(FileChannel
the channel to drain
channel
,
long
the position to drain from
position
,
long
the number of bytes
count
)

Attempt to drain the given number of bytes from the file channel.

public static void
flushBlocking(SuspendableWriteChannel
the writable channel
channel
)

Simple utility method to execute a blocking flush on a writable channel.

public static boolean

Returns:

true if the channel was successfully flushed, false if the timeout was reached
flushBlocking
(SuspendableWriteChannel
the writable channel
channel
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking flush on a writable channel.

public static <
the option value type
T
>
T

Returns:

the value
getOption
(Configurable
the configurable target
configurable
,
Option<T>
the option
option
,
T
the default value
defaultValue
)

Get an option value from a configurable target.

public static boolean

Returns:

the value
getOption
(Configurable
the configurable target
configurable
,
Option<Boolean>
the option
option
,
boolean
the default value
defaultValue
)

Get an option value from a configurable target.

public static int

Returns:

the value
getOption
(Configurable
the configurable target
configurable
,
Option<Integer>
the option
option
,
int
the default value
defaultValue
)

Get an option value from a configurable target.

public static long

Returns:

the value
getOption
(Configurable
the configurable target
configurable
,
Option<Long>
the option
option
,
long
the default value
defaultValue
)

Get an option value from a configurable target.

public static <
the channel type
C extends ReadableByteChannel & SuspendableReadChannel
>
int

Returns:

the number of bytes read
readBlocking
(C
the channel to read from
channel
,
ByteBuffer
the buffer into which bytes are to be transferred
buffer
)

Simple utility method to execute a blocking read on a readable byte channel.

public static <
the channel type
C extends ReadableByteChannel & SuspendableReadChannel
>
int

Returns:

the number of bytes read
readBlocking
(C
the channel to read from
channel
,
ByteBuffer
the buffer into which bytes are to be transferred
buffer
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking read on a readable byte channel with a timeout.

public static <
the channel type
C extends ScatteringByteChannel & SuspendableReadChannel
>
long

Returns:

the number of bytes read
readBlocking
(C
the channel to read from
channel
,
ByteBuffer[]
the buffers into which bytes are to be transferred
buffers
,
int
the first buffer to use
offs
,
int
the number of buffers to use
len
)

Simple utility method to execute a blocking read on a scattering byte channel.

public static <
the channel type
C extends ScatteringByteChannel & SuspendableReadChannel
>
long

Returns:

the number of bytes read
readBlocking
(C
the channel to read from
channel
,
ByteBuffer[]
the buffers into which bytes are to be transferred
buffers
,
int
the first buffer to use
offs
,
int
the number of buffers to use
len
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking read on a scattering byte channel with a timeout.

public static <
the channel type
C extends ReadableMessageChannel
>
int

Returns:

the number of bytes read
receiveBlocking
(C
the channel to read from
channel
,
ByteBuffer
the buffer into which bytes are to be transferred
buffer
)

Simple utility method to execute a blocking receive on a readable message channel.

public static <
the channel type
C extends ReadableMessageChannel
>
int

Returns:

the number of bytes read
receiveBlocking
(C
the channel to read from
channel
,
ByteBuffer
the buffer into which bytes are to be transferred
buffer
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking receive on a readable message channel with a timeout.

public static <
the channel type
C extends ReadableMessageChannel
>
long

Returns:

the number of bytes read
receiveBlocking
(C
the channel to read from
channel
,
ByteBuffer[]
the buffers into which bytes are to be transferred
buffers
,
int
the first buffer to use
offs
,
int
the number of buffers to use
len
)

Simple utility method to execute a blocking receive on a readable message channel.

public static <
the channel type
C extends ReadableMessageChannel
>
long

Returns:

the number of bytes read
receiveBlocking
(C
the channel to read from
channel
,
ByteBuffer[]
the buffers into which bytes are to be transferred
buffers
,
int
the first buffer to use
offs
,
int
the number of buffers to use
len
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking receive on a readable message channel with a timeout.

public static void
resumeReadsAsync(final SuspendableReadChannel
the channel to resume
channel
)

Resume reads asynchronously.

public static void
resumeWritesAsync(final SuspendableWriteChannel
the channel to resume
channel
)

Resume writes asynchronously.

public static <
the channel type
C extends WritableMessageChannel
>
void
sendBlocking(C
the channel to write on
channel
,
ByteBuffer
the data to write
buffer
)

Simple utility method to execute a blocking send on a message channel.

public static <
the channel type
C extends WritableMessageChannel
>
boolean

Returns:

the write result
sendBlocking
(C
the channel to write on
channel
,
ByteBuffer
the data to write
buffer
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking send on a message channel with a timeout.

public static <
the channel type
C extends WritableMessageChannel
>
void
sendBlocking(C
the channel to write on
channel
,
ByteBuffer[]
the data to write
buffers
,
int
the index of the first buffer to write
offs
,
int
the number of buffers to write
len
)

Simple utility method to execute a blocking gathering send on a message channel.

public static <
the channel type
C extends WritableMessageChannel
>
boolean

Returns:

true if the message was written before the timeout
sendBlocking
(C
the channel to write on
channel
,
ByteBuffer[]
the data to write
buffers
,
int
the index of the first buffer to write
offs
,
int
the number of buffers to write
len
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking gathering send on a message channel with a timeout.

public static <
the channel type
T extends AcceptingChannel<?>
>
void
setAcceptListener(T
the channel
channel
,
ChannelListener<? super T>
the listener to set
listener
)

Set the accept listener for a channel (type-safe).

public static <
the channel type
T extends CloseableChannel
>
void
setCloseListener(T
the channel
channel
,
ChannelListener<? super T>
the listener to set
listener
)

Set the close listener for a channel (type-safe).

public static <
the channel type
T extends SuspendableReadChannel
>
void
setReadListener(T
the channel
channel
,
ChannelListener<? super T>
the listener to set
listener
)

Set the read listener for a channel (type-safe).

public static <
the channel type
T extends SuspendableWriteChannel
>
void
setWriteListener(T
the channel
channel
,
ChannelListener<? super T>
the listener to set
listener
)

Set the write listener for a channel (type-safe).

public static void
shutdownWritesBlocking(SuspendableWriteChannel
the writable channel
channel
)

Simple utility method to execute a blocking write shutdown on a writable channel.

public static boolean

Returns:

true if the channel was successfully flushed, false if the timeout was reached
shutdownWritesBlocking
(SuspendableWriteChannel
the writable channel
channel
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking write shutdown on a writable channel.

public static void
transferBlocking(StreamSinkChannel
the destination channel
destination
,
FileChannel
the source file channel
source
,
long
the start position in the source file
startPosition
,
final long
the number of bytes to transfer
count
)

Transfer bytes between two channels efficiently, blocking if necessary.

public static void
transferBlocking(FileChannel
the destination file channel
destination
,
StreamSourceChannel
the source channel
source
,
long
the start position in the destination file
startPosition
,
final long
the number of bytes to transfer
count
)

Transfer bytes between two channels efficiently, blocking if necessary.

public static long

Returns:

the number of bytes actually transferred (will be fewer than count if EOF was reached)
transferBlocking
(StreamSinkChannel
the destination channel
destination
,
StreamSourceChannel
the source channel
source
,
ByteBuffer
the buffer to transfer through,
throughBuffer
,
long
the number of bytes to transfer
count
)

Transfer bytes between two channels efficiently, blocking if necessary.

public static <
the type to unwrap
T extends Channel
>
T

Returns:

the unwrapped type, or null if the given type is not wrapped
unwrap
(Class<T>
the class to unwrap
targetType
,
Channel
the channel
channel
)

Unwrap a nested channel type.

public static ByteChannel

Returns:

the wrapped channel
wrapByteChannel
(final ByteChannel
the original
original
)

Create a wrapper for a byte channel which does not expose other methods.

public static <
the channel type
C extends WritableByteChannel & SuspendableWriteChannel
>
int

Returns:

the number of bytes written
writeBlocking
(C
the channel to write on
channel
,
ByteBuffer
the data to write
buffer
)

Simple utility method to execute a blocking write on a byte channel.

public static <
the channel type
C extends WritableByteChannel & SuspendableWriteChannel
>
int

Returns:

the number of bytes written
writeBlocking
(C
the channel to write on
channel
,
ByteBuffer
the data to write
buffer
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking write on a byte channel with a timeout.

public static <
the channel type
C extends GatheringByteChannel & SuspendableWriteChannel
>
long

Returns:

the number of bytes written
writeBlocking
(C
the channel to write on
channel
,
ByteBuffer[]
the data to write
buffers
,
int
the index of the first buffer to write
offs
,
int
the number of buffers to write
len
)

Simple utility method to execute a blocking write on a gathering byte channel.

public static <
the channel type
C extends GatheringByteChannel & SuspendableWriteChannel
>
long

Returns:

the number of bytes written
writeBlocking
(C
the channel to write on
channel
,
ByteBuffer[]
the data to write
buffers
,
int
the index of the first buffer to write
offs
,
int
the number of buffers to write
len
,
long
the amount of time to wait
time
,
TimeUnit
the unit of time to wait
unit
)

Simple utility method to execute a blocking write on a gathering byte channel with a timeout.

public static int

Returns:

The number of bytes written
writeFinalBasic
(StreamSinkChannel
The channel
channel
,
ByteBuffer
The buffer
src
)

Writes out the data in the buffer to the channel.

public static long

Returns:

The number of bytes written
writeFinalBasic
(StreamSinkChannel
The channel
channel
,
ByteBuffer[]
The buffers
srcs
,
int
The offset into the srcs array
offset
,
int
The number buffers to write
length
)

Writes out the data in the buffer to the channel.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait