Package org.xnio.conduits

# Class BlockingStreamSinkConduit

java.lang.Object
org.xnio.conduits.AbstractConduit<StreamSinkConduit>
org.xnio.conduits.AbstractSinkConduit<StreamSinkConduit>
org.xnio.conduits.AbstractStreamSinkConduit<StreamSinkConduit>
org.xnio.conduits.BlockingStreamSinkConduit

All Implemented Interfaces:
  `Conduit`, `SinkConduit`, `StreamSinkConduit`

public final class BlockingStreamSinkConduit extends AbstractStreamSinkConduit<StreamSinkConduit>

Author:
  David M. Lloyd

## Field Summary

### Fields inherited from class org.xnio.conduits.AbstractConduit

`next`

## Constructor Summary

Constructors
Constructor
Description
`BlockingStreamSinkConduit(StreamSinkConduit next)`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`flush()`
Flush out any unwritten, buffered output.
`boolean`
`isWriteResumed()`
Determine whether write notifications are currently enabled.
`void`
`resumeWrites()`
Indicate that the conduit's `WriteReadyHandler` should be invoked as soon as data can be written without blocking.
`void`
`suspendWrites()`
Indicate that calling the conduit's `WriteReadyHandler` should be suspended.
`long`
`transferFrom(FileChannel src, long position, long count)`
Transfer bytes into this conduit from the given file.
`long`
`transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer)`
Transfers bytes from the given channel source.
`void`
`wakeupWrites()`
Indicate that the conduit's `WriteReadyHandler` should be invoked immediately, and then again as soon as data can be written without blocking.
`int`
`write(ByteBuffer src)`
Writes a sequence of bytes to this conduit from the given buffer.
`long`
`write(ByteBuffer[] srcs, int offs, int len)`
Writes a sequence of bytes to this conduit from the given buffers.
`int`
`writeFinal(ByteBuffer src)`
Writes some data to the conduit, with the same semantics as `StreamSinkConduit.write(java.nio.ByteBuffer)`.
`long`
`writeFinal(ByteBuffer[] srcs, int offset, int length)`
Writes some data to the conduit, with the same semantics as `StreamSinkConduit.write(java.nio.ByteBuffer[], int, int)`.

### Methods inherited from class org.xnio.conduits.AbstractSinkConduit

`awaitWritable, awaitWritable, getWriteThread, isWriteShutdown, setWriteReadyHandler, terminateWrites, truncateWrites`

### Methods inherited from class org.xnio.conduits.AbstractConduit

`getWorker`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface org.xnio.conduits.Conduit

`getWorker`

### Methods inherited from interface org.xnio.conduits.SinkConduit

`awaitWritable, awaitWritable, getWriteThread, isWriteShutdown, setWriteReadyHandler, terminateWrites, truncateWrites`

## Constructor Details

### BlockingStreamSinkConduit

public BlockingStreamSinkConduit(StreamSinkConduit next)

## Method Details

### transferFrom

public long transferFrom(FileChannel src, long position, long count) throws IOException
Description copied from interface: `StreamSinkConduit`
Transfer bytes into this conduit from the given file.

Specified by:
  `transferFrom` in interface `StreamSinkConduit`
Overrides:
  `transferFrom` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `src` - the file to read from
  `position` - the position within the file from which the transfer is to begin
  `count` - the number of bytes to be transferred
Returns:
  the number of bytes (possibly 0) that were actually transferred
Throws:
  `IOException` - if an I/O error occurs

### transferFrom

public long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException
Description copied from interface: `StreamSinkConduit`
Transfers bytes from the given channel source. On entry, `throughBuffer` will be cleared. On exit, the buffer will be flipped for emptying, and may be empty or may contain data. If this method returns a value less than `count`, then the remaining data in `throughBuffer` may contain data read from `source` which must be written to this channel to complete the operation.

Specified by:
  `transferFrom` in interface `StreamSinkConduit`
Overrides:
  `transferFrom` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `source` - the source to read from
  `count` - the number of bytes to be transferred
  `throughBuffer` - the buffer to copy through.
Returns:
  the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached
Throws:
  `IOException` - if an I/O error occurs

### write

public int write(ByteBuffer src) throws IOException
Description copied from interface: `StreamSinkConduit`
Writes a sequence of bytes to this conduit from the given buffer.

Specified by:
  `write` in interface `StreamSinkConduit`
Overrides:
  `write` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `src` - the buffer containing data to write
Returns:
  the number of bytes written, possibly 0
Throws:
  `IOException` - if an error occurs

### write

public long write(ByteBuffer[] srcs, int offs, int len) throws IOException
Description copied from interface: `StreamSinkConduit`
Writes a sequence of bytes to this conduit from the given buffers.

Specified by:
  `write` in interface `StreamSinkConduit`
Overrides:
  `write` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `srcs` - the buffers containing data to write
  `offs` - the offset into the buffer array
  `len` - the number of buffers to write
Returns:
  the number of bytes written, possibly 0
Throws:
  `IOException` - if an error occurs

### writeFinal

public int writeFinal(ByteBuffer src) throws IOException
Description copied from interface: `StreamSinkConduit`
Writes some data to the conduit, with the same semantics as `StreamSinkConduit.write(java.nio.ByteBuffer)`. If all the data is written out then the conduit will have its writes terminated. Semantically this method is equivalent to: `int rem = src.remaining(); int written = conduit.write(src); if(written == rem) { conduit.terminateWrites() }`

Specified by:
  `writeFinal` in interface `StreamSinkConduit`
Overrides:
  `writeFinal` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `src` - The data to write
Returns:
  The amount of data that was actually written.
Throws:
  `IOException`

### writeFinal

public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
Description copied from interface: `StreamSinkConduit`
Writes some data to the conduit, with the same semantics as `StreamSinkConduit.write(java.nio.ByteBuffer[], int, int)`. If all the data is written out then the conduit will have its writes terminated.

Specified by:
  `writeFinal` in interface `StreamSinkConduit`
Overrides:
  `writeFinal` in class `AbstractStreamSinkConduit<StreamSinkConduit>`
Parameters:
  `srcs` - The buffers from which bytes are to be retrieved
  `offset` - The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than `srcs.length`
  `length` - The maximum number of buffers to be accessed; must be non-negative and no larger than `srcs.length` - `offset`
Returns:
  The amount of data that was actually written
Throws:
  `IOException`

### flush

public boolean flush() throws IOException
Description copied from interface: `SinkConduit`
Flush out any unwritten, buffered output.

Specified by:
  `flush` in interface `SinkConduit`
Overrides:
  `flush` in class `AbstractSinkConduit<StreamSinkConduit>`
Returns:
  `true` if everything is flushed, `false` otherwise
Throws:
  `IOException` - if flush fails

### resumeWrites

public void resumeWrites()
Description copied from interface: `SinkConduit`
Indicate that the conduit's `WriteReadyHandler` should be invoked as soon as data can be written without blocking.

Specified by:
  `resumeWrites` in interface `SinkConduit`
Overrides:
  `resumeWrites` in class `AbstractSinkConduit<StreamSinkConduit>`

### suspendWrites

public void suspendWrites()
Description copied from interface: `SinkConduit`
Indicate that calling the conduit's `WriteReadyHandler` should be suspended.

Specified by:
  `suspendWrites` in interface `SinkConduit`
Overrides:
  `suspendWrites` in class `AbstractSinkConduit<StreamSinkConduit>`

### wakeupWrites

public void wakeupWrites()
Description copied from interface: `SinkConduit`
Indicate that the conduit's `WriteReadyHandler` should be invoked immediately, and then again as soon as data can be written without blocking.

Specified by:
  `wakeupWrites` in interface `SinkConduit`
Overrides:
  `wakeupWrites` in class `AbstractSinkConduit<StreamSinkConduit>`

### isWriteResumed

public boolean isWriteResumed()
Description copied from interface: `SinkConduit`
Determine whether write notifications are currently enabled.

Specified by:
  `isWriteResumed` in interface `SinkConduit`
Overrides:
  `isWriteResumed` in class `AbstractSinkConduit<StreamSinkConduit>`
Returns:
  `true` if write notifications are enabled