Package org.xnio.conduits
Class Conduits
java.lang.Object
org.xnio.conduits.Conduits
General utility methods for manipulating conduits.
- Author:
- David M. Lloyd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic longdrain(StreamSourceConduit conduit, long count) Attempt to drain the given number of bytes from the stream source conduit.static booleansendFinalBasic(MessageSinkConduit conduit, ByteBuffer src) Writes a message to the conduit, and terminates writes if the send was successfully.static booleansendFinalBasic(MessageSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) Writes a message to the conduit, and terminates writes if the send was successfully.static longtransfer(ReadableByteChannel source, long count, ByteBuffer throughBuffer, StreamSinkConduit sink) Platform-independent channel-to-channel transfer method.static longtransfer(StreamSourceConduit source, long count, ByteBuffer throughBuffer, WritableByteChannel sink) Platform-independent channel-to-channel transfer method.static intwriteFinalBasic(StreamSinkConduit conduit, ByteBuffer src) Writes the buffer to the conduit, and terminates writes if all the data is writtenstatic longwriteFinalBasic(StreamSinkConduit conduit, ByteBuffer[] srcs, int offset, int length) Writes the buffer to the conduit, and terminates writes if all the data is written
-
Constructor Details
-
Conduits
public Conduits()
-
-
Method Details
-
transfer
public static long transfer(StreamSourceConduit source, long count, ByteBuffer throughBuffer, WritableByteChannel sink) throws IOException Platform-independent channel-to-channel transfer method. Uses regularreadandwriteoperations to move bytes from thesourcechannel to thesinkchannel. After this call, thethroughBuffershould be checked for remaining bytes; if there are any, they should be written to thesinkchannel 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- the source channel to read bytes fromcount- the number of bytes to transfer (must be >=0L)throughBuffer- the buffer to transfer through (must not benull)sink- the sink channel to write bytes to- Returns:
- the number of bytes actually transferred (possibly 0)
- Throws:
IOException- if an I/O error occurs during the transfer of bytes
-
transfer
public static long transfer(ReadableByteChannel source, long count, ByteBuffer throughBuffer, StreamSinkConduit sink) throws IOException Platform-independent channel-to-channel transfer method. Uses regularreadandwriteoperations to move bytes from thesourcechannel to thesinkchannel. After this call, thethroughBuffershould be checked for remaining bytes; if there are any, they should be written to thesinkchannel 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- the source channel to read bytes fromcount- the number of bytes to transfer (must be >=0L)throughBuffer- the buffer to transfer through (must not benull)sink- the sink channel to write bytes to- Returns:
- the number of bytes actually transferred (possibly 0)
- Throws:
IOException- if an I/O error occurs during the transfer of bytes
-
writeFinalBasic
Writes the buffer to the conduit, and terminates writes if all the data is written- Parameters:
conduit- The conduit to write tosrc- The data to write- Returns:
- The number of bytes written
- Throws:
IOException
-
writeFinalBasic
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- The conduit to write tosrcs- The data to writeoffset- The offset into the data arraylength- The number of buffers to write- Returns:
- The number of bytes written
- Throws:
IOException
-
sendFinalBasic
Writes a message to the conduit, and terminates writes if the send was successfully.- Parameters:
conduit- The conduitsrc- The message buffer- Returns:
trueif the message was sent successfully- Throws:
IOException
-
sendFinalBasic
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- The conduitsrcs- The message buffersoffset- The offset in the message bufferslength- The number of buffers to send- Returns:
trueif the message was sent successfully- Throws:
IOException
-
drain
Attempt to drain the given number of bytes from the stream source conduit.- Parameters:
conduit- the conduit to draincount- the number of bytes- Returns:
- the number of bytes drained, 0 if reading the conduit would block, or -1 if the EOF was reached
- Throws:
IOException- if an error occurs
-