Package org.xnio.conduits

# Class PushBackStreamSourceConduit

java.lang.Object
org.xnio.conduits.AbstractConduit<StreamSourceConduit>
org.xnio.conduits.AbstractSourceConduit<StreamSourceConduit>
org.xnio.conduits.AbstractStreamSourceConduit<StreamSourceConduit>
org.xnio.conduits.PushBackStreamSourceConduit

All Implemented Interfaces:
  `Conduit`, `SourceConduit`, `StreamSourceConduit`

public final class PushBackStreamSourceConduit extends AbstractStreamSourceConduit<StreamSourceConduit> implements StreamSourceConduit
A stream source conduit which allows buffers to be "pushed back" to the head of the stream.

Author:
  David M. Lloyd

## Field Summary

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

`next`

## Constructor Summary

Constructors
Constructor
Description
`PushBackStreamSourceConduit(StreamSourceConduit next)`
Construct a new instance.

## Method Summary

Modifier and Type
Method
Description
`void`
`awaitReadable()`
Block until this channel becomes readable again.
`void`
`awaitReadable(long time, TimeUnit timeUnit)`
Block until this conduit becomes readable again, or until the timeout expires.
`void`
`pushBack(Pooled<ByteBuffer> pooledBuffer)`
Push a buffer back to the head of the stream.
`int`
`read(ByteBuffer dst)`
Read a sequence of bytes from this conduit to the given buffer.
`long`
`read(ByteBuffer[] dsts, int offs, int len)`
Read a sequence of bytes from this conduit to the given buffers.
`void`
`resumeReads()`
Indicate that the conduit's `ReadReadyHandler` should be invoked as soon as data can be read without blocking.
`void`
`setReadReadyHandler(ReadReadyHandler handler)`
Set the handler which should receive readiness notifications.
`void`
`terminateReads()`
Indicate that no more data will be read from this conduit.
`long`
`transferTo(long position, long count, FileChannel target)`
Transfers bytes into the given file from this channel.
`long`
`transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel target)`
Transfers bytes into the given channel target.

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

`getReadThread, isReadResumed, isReadShutdown, suspendReads, wakeupReads`

### 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.SourceConduit

`getReadThread, isReadResumed, isReadShutdown, suspendReads, wakeupReads`

## Constructor Details

### PushBackStreamSourceConduit

public PushBackStreamSourceConduit(StreamSourceConduit next)
Construct a new instance.

Parameters:
  `next` - the delegate conduit to set

## Method Details

### resumeReads

public void resumeReads()
Description copied from interface: `SourceConduit`
Indicate that the conduit's `ReadReadyHandler` should be invoked as soon as data can be read without blocking.

Specified by:
  `resumeReads` in interface `SourceConduit`
Overrides:
  `resumeReads` in class `AbstractSourceConduit<StreamSourceConduit>`

### read

public int read(ByteBuffer dst) throws IOException
Description copied from interface: `StreamSourceConduit`
Read a sequence of bytes from this conduit to the given buffer.

Specified by:
  `read` in interface `StreamSourceConduit`
Overrides:
  `read` in class `AbstractStreamSourceConduit<StreamSourceConduit>`
Returns:
  the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's `SourceConduit.terminateReads()` method was previously called
Throws:
  `IOException` - if an error occurs

### read

public long read(ByteBuffer[] dsts, int offs, int len) throws IOException
Description copied from interface: `StreamSourceConduit`
Read a sequence of bytes from this conduit to the given buffers.

Specified by:
  `read` in interface `StreamSourceConduit`
Overrides:
  `read` in class `AbstractStreamSourceConduit<StreamSourceConduit>`
Parameters:
  `offs` - the offset into the buffer array
  `len` - the number of buffers to fill
Returns:
  the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's `SourceConduit.terminateReads()` method was previously called
Throws:
  `IOException` - if an error occurs

### transferTo

public long transferTo(long position, long count, FileChannel target) throws IOException
Description copied from interface: `StreamSourceConduit`
Transfers bytes into the given file from this channel.

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

### transferTo

public long transferTo(long count, ByteBuffer throughBuffer, StreamSinkChannel target) throws IOException
Description copied from interface: `StreamSourceConduit`
Transfers bytes into the given channel target. On entry, `throughBuffer` will be cleared. On exit, the buffer will be flipped for emptying, and may possibly 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 this channel which must be written to `target` to complete the operation.

Specified by:
  `transferTo` in interface `StreamSourceConduit`
Overrides:
  `transferTo` in class `AbstractStreamSourceConduit<StreamSourceConduit>`
Parameters:
  `count` - the number of bytes to be transferred
  `throughBuffer` - the buffer to copy through.
  `target` - the destination to write to
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

### awaitReadable

public void awaitReadable() throws IOException
Description copied from interface: `SourceConduit`
Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Specified by:
  `awaitReadable` in interface `SourceConduit`
Overrides:
  `awaitReadable` in class `AbstractSourceConduit<StreamSourceConduit>`
Throws:
  `IOException` - if an I/O error occurs

### awaitReadable

public void awaitReadable(long time, TimeUnit timeUnit) throws IOException
Description copied from interface: `SourceConduit`
Block until this conduit becomes readable again, or until the timeout expires. This method may return spuriously before the conduit becomes readable or the timeout expires.

Specified by:
  `awaitReadable` in interface `SourceConduit`
Overrides:
  `awaitReadable` in class `AbstractSourceConduit<StreamSourceConduit>`
Parameters:
  `time` - the time to wait
  `timeUnit` - the time unit
Throws:
  `IOException` - if an I/O error occurs

### terminateReads

public void terminateReads() throws IOException
Description copied from interface: `SourceConduit`
Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Specified by:
  `terminateReads` in interface `SourceConduit`
Overrides:
  `terminateReads` in class `AbstractSourceConduit<StreamSourceConduit>`
Throws:
  `IOException` - if there was a problem

### setReadReadyHandler

public void setReadReadyHandler(ReadReadyHandler handler)
Description copied from interface: `SourceConduit`
Set the handler which should receive readiness notifications. A filter may pass this invocation on to the filter it wraps, or it may substitute itself.

Specified by:
  `setReadReadyHandler` in interface `SourceConduit`
Overrides:
  `setReadReadyHandler` in class `AbstractSourceConduit<StreamSourceConduit>`

### pushBack

public void pushBack(Pooled<ByteBuffer> pooledBuffer)
Push a buffer back to the head of the stream. Once the buffer data is consumed, it will be released back to its original pool (if any).

Parameters:
  `pooledBuffer` - the buffer to push back