Top Description Fields Constructors Methods
org.xnio.conduits

public final Class Conduits

extends Object
Class Inheritance
Imports
org.xnio.Buffers, java.io.FileNotFoundException, .FileOutputStream, .IOError, .IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, .ReadableByteChannel, .WritableByteChannel, java.security.AccessController, .PrivilegedAction, java.util.Locale

General utility methods for manipulating conduits.
Author
David M. Lloyd

Field Summary

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static long

Returns:

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

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

public static boolean

Returns:

true if the message was sent successfully
sendFinalBasic
(MessageSinkConduit
The conduit
conduit
,
ByteBuffer
The message buffer
src
)

Writes a message to the conduit, and terminates writes if the send was successfully.

public static boolean

Returns:

true if the message was sent successfully
sendFinalBasic
(MessageSinkConduit
The conduit
conduit
,
ByteBuffer[]
The message buffers
srcs
,
int
The offset in the message buffers
offset
,
int
The number of buffers to send
length
)

Writes a message to the conduit, and terminates writes if the send was successfully.

public static long

Returns:

the number of bytes actually transferred (possibly 0)
transfer
(final StreamSourceConduit
the source channel to read bytes from
source
,
final long
the number of bytes to transfer (must be >= 0L)
count
,
final ByteBuffer
the buffer to transfer through (must not be null)
throughBuffer
,
final WritableByteChannel
the sink channel to write bytes to
sink
)

Platform-independent channel-to-channel transfer method.

public static long

Returns:

the number of bytes actually transferred (possibly 0)
transfer
(final ReadableByteChannel
the source channel to read bytes from
source
,
final long
the number of bytes to transfer (must be >= 0L)
count
,
final ByteBuffer
the buffer to transfer through (must not be null)
throughBuffer
,
final StreamSinkConduit
the sink channel to write bytes to
sink
)

Platform-independent channel-to-channel transfer method.

public static int

Returns:

The number of bytes written
writeFinalBasic
(StreamSinkConduit
The conduit to write to
conduit
,
ByteBuffer
The data to write
src
)

Writes the buffer to the conduit, and terminates writes if all the data is written

public static long

Returns:

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

Writes the buffer to the conduit, and terminates writes if all the data is written

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DRAIN_BUFFERback to summary
private static final ByteBuffer DRAIN_BUFFER
NULL_FILE_CHANNELback to summary
private static final FileChannel NULL_FILE_CHANNEL

Constructor Detail

Conduitsback to summary
public Conduits()

Method Detail

drainback to summary
public static long drain(StreamSourceConduit conduit, long count) throws IOException

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

Parameters
conduit:StreamSourceConduit

the conduit to drain

count:long

the number of bytes

Returns:long

the number of bytes drained, 0 if reading the conduit would block, or -1 if the EOF was reached

Exceptions
IOException:
if an error occurs
sendFinalBasicback to summary
public static boolean sendFinalBasic(MessageSinkConduit conduit, ByteBuffer src) throws IOException

Writes a message to the conduit, and terminates writes if the send was successfully.

Parameters
conduit:MessageSinkConduit

The conduit

src:ByteBuffer

The message buffer

Returns:boolean

true if the message was sent successfully

sendFinalBasicback to summary
public static boolean sendFinalBasic(MessageSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) throws IOException

Writes a message to the conduit, and terminates writes if the send was successfully.

Parameters
conduit:MessageSinkConduit

The conduit

srcs:ByteBuffer[]

The message buffers

offset:int

The offset in the message buffers

length:int

The number of buffers to send

Returns:boolean

true if the message was sent successfully

transferback to summary
public static long transfer(final StreamSourceConduit source, final long count, final ByteBuffer throughBuffer, final WritableByteChannel sink) throws IOException

Platform-independent channel-to-channel transfer method. Uses regular read and write operations to move bytes from the source channel to the sink channel. After this call, the throughBuffer should be checked for remaining bytes; if there are any, they should be written to the sink channel before proceeding. This method may be used with NIO channels, XNIO channels, or a combination of the two.

If either or both of the given channels are blocking channels, then this method may block.

Parameters
source:StreamSourceConduit

the source channel to read bytes from

count:long

the number of bytes to transfer (must be >= 0L)

throughBuffer:ByteBuffer

the buffer to transfer through (must not be null)

sink:WritableByteChannel

the sink channel to write bytes to

Returns:long

the number of bytes actually transferred (possibly 0)

Exceptions
IOException:
if an I/O error occurs during the transfer of bytes
transferback to summary
public static long transfer(final ReadableByteChannel source, final long count, final ByteBuffer throughBuffer, final StreamSinkConduit sink) throws IOException

Platform-independent channel-to-channel transfer method. Uses regular read and write operations to move bytes from the source channel to the sink channel. After this call, the throughBuffer should be checked for remaining bytes; if there are any, they should be written to the sink channel before proceeding. This method may be used with NIO channels, XNIO channels, or a combination of the two.

If either or both of the given channels are blocking channels, then this method may block.

Parameters
source:ReadableByteChannel

the source channel to read bytes from

count:long

the number of bytes to transfer (must be >= 0L)

throughBuffer:ByteBuffer

the buffer to transfer through (must not be null)

sink:StreamSinkConduit

the sink channel to write bytes to

Returns:long

the number of bytes actually transferred (possibly 0)

Exceptions
IOException:
if an I/O error occurs during the transfer of bytes
writeFinalBasicback to summary
public static int writeFinalBasic(StreamSinkConduit conduit, ByteBuffer src) throws IOException

Writes the buffer to the conduit, and terminates writes if all the data is written

Parameters
conduit:StreamSinkConduit

The conduit to write to

src:ByteBuffer

The data to write

Returns:int

The number of bytes written

writeFinalBasicback to summary
public static long writeFinalBasic(StreamSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) throws IOException

Writes the buffer to the conduit, and terminates writes if all the data is written

Parameters
conduit:StreamSinkConduit

The conduit to write to

srcs:ByteBuffer[]

The data to write

offset:int

The offset into the data array

length:int

The number of buffers to write

Returns:long

The number of bytes written