Top Description Inners Fields Constructors Methods
org.xnio.conduits

public final Class PushBackStreamSourceConduit

extends AbstractStreamSourceConduit<StreamSourceConduit>
implements StreamSourceConduit
Class Inheritance
All Implemented Interfaces
org.xnio.conduits.StreamSourceConduit, org.xnio.conduits.SourceConduit, org.xnio.conduits.Conduit
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.util.concurrent.TimeUnit, org.xnio.Buffers, .Pooled, org.xnio.channels.StreamSinkChannel

A stream source conduit which allows buffers to be "pushed back" to the head of the stream.
Author
David M. Lloyd

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private StreamSourceConduit
private boolean

Constructor Summary

AccessConstructor and Description
public
PushBackStreamSourceConduit(final StreamSourceConduit
the delegate conduit to set
next
)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
public void
awaitReadable()

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again.

public void
awaitReadable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this conduit becomes readable again, or until the timeout expires.

public void
pushBack(Pooled<ByteBuffer>
the buffer to push back
pooledBuffer
)
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Push a buffer back to the head of the stream.

public int
read(final ByteBuffer
the buffer to fill with data from the conduit
dst
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

public long
read(final ByteBuffer[]
the buffers to fill with data from the conduit
dsts
,
final int
the offset into the buffer array
offs
,
final int
the number of buffers to fill
len
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

public void
resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

public void
setReadReadyHandler(final ReadReadyHandler
the filter to receive readiness notifications
handler
)

Overrides org.xnio.conduits.AbstractSourceConduit.setReadReadyHandler.

Implements org.xnio.conduits.SourceConduit.setReadReadyHandler.

Set the handler which should receive readiness notifications.

public void
terminateReads()

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit.

public long
transferTo(final long
the position within the file from which the transfer is to begin
position
,
final long
the number of bytes to be transferred
count
,
final FileChannel
the file to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

public long
transferTo(final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
,
final StreamSinkChannel
the destination to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target.

Field Detail

currentback to summary
private StreamSourceConduit current
shutdownback to summary
private boolean shutdown

Constructor Detail

PushBackStreamSourceConduitback to summary
public PushBackStreamSourceConduit(final StreamSourceConduit next)

Construct a new instance.

Parameters
next:StreamSourceConduit

the delegate conduit to set

Method Detail

awaitReadableback to summary
public void awaitReadable() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Exceptions
IOException:
if an I/O error occurs
awaitReadableback to summary
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

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.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Exceptions
IOException:
if an I/O error occurs
pushBackback to summary
public void pushBack(Pooled<ByteBuffer> pooledBuffer)

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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:Pooled<ByteBuffer>

the buffer to push back

readback to summary
public int read(final ByteBuffer dst) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

Parameters
dst:ByteBuffer

the buffer to fill with data from the conduit

Returns:int

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
readback to summary
public long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

Parameters
dsts:ByteBuffer[]

the buffers to fill with data from the conduit

offs:int

the offset into the buffer array

len:int

the number of buffers to fill

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
resumeReadsback to summary
public void resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Doc from org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

setReadReadyHandlerback to summary
public void setReadReadyHandler(final ReadReadyHandler handler)

Overrides org.xnio.conduits.AbstractSourceConduit.setReadReadyHandler.

Implements org.xnio.conduits.SourceConduit.setReadReadyHandler.

Doc from org.xnio.conduits.SourceConduit.setReadReadyHandler.

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.

Parameters
handler:ReadReadyHandler

the filter to receive readiness notifications

terminateReadsback to summary
public void terminateReads() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Doc from org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Exceptions
IOException:
if there was a problem
transferToback to summary
public long transferTo(final long position, final long count, final FileChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

Parameters
position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

target:FileChannel

the file to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred

Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

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.

Parameters
count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

target:StreamSinkChannel

the destination to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Exceptions
IOException:
if an I/O error occurs
org.xnio.conduits back to summary

pack-priv Class PushBackStreamSourceConduit.BufferConduit

extends AbstractStreamSourceConduit<StreamSourceConduit>
implements StreamSourceConduit
Class Inheritance
All Implemented Interfaces
org.xnio.conduits.StreamSourceConduit, org.xnio.conduits.SourceConduit, org.xnio.conduits.Conduit

Field Summary

Modifier and TypeField and Description
private final Pooled<ByteBuffer>
pooledBuffer

References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Constructor Summary

AccessConstructor and Description
pack-priv
BufferConduit(final StreamSourceConduit next, final Pooled<ByteBuffer> pooledBuffer)
References Deprecated Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

Method Summary

Modifier and TypeMethod and Description
public void
awaitReadable(final long
the time to wait
time
,
final TimeUnit
the time unit
timeUnit
)

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this conduit becomes readable again, or until the timeout expires.

public void
awaitReadable()

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again.

private final void
public int
read(final ByteBuffer
the buffer to fill with data from the conduit
dst
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

public long
read(final ByteBuffer[]
the buffers to fill with data from the conduit
dsts
,
final int
the offset into the buffer array
offs
,
final int
the number of buffers to fill
len
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

public void
resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

public void
terminateReads()

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit.

public long
transferTo(long
the position within the file from which the transfer is to begin
position
,
long
the number of bytes to be transferred
count
,
final FileChannel
the file to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

public long
transferTo(final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
,
final StreamSinkChannel
the destination to write to
target
)

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given channel target.

Field Detail

pooledBufferback to summary
private final Pooled<ByteBuffer> pooledBuffer

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Constructor Detail

BufferConduitback to summary
pack-priv BufferConduit(final StreamSourceConduit next, final Pooled<ByteBuffer> pooledBuffer)

References Deprecated

Pooled is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Method Detail

awaitReadableback to summary
public void awaitReadable(final long time, final TimeUnit timeUnit) throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

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.

Parameters
time:long

the time to wait

timeUnit:TimeUnit

the time unit

Exceptions
IOException:
if an I/O error occurs
awaitReadableback to summary
public void awaitReadable() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.awaitReadable.

Implements org.xnio.conduits.SourceConduit.awaitReadable.

Doc from org.xnio.conduits.SourceConduit.awaitReadable.

Block until this channel becomes readable again. This method may return spuriously before the channel becomes readable.

Exceptions
IOException:
if an I/O error occurs
moveToNextback to summary
private final void moveToNext()
readback to summary
public int read(final ByteBuffer dst) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffer.

Parameters
dst:ByteBuffer

the buffer to fill with data from the conduit

Returns:int

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
readback to summary
public long read(final ByteBuffer[] dsts, final int offs, final int len) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.read.

Implements org.xnio.conduits.StreamSourceConduit.read.

Doc from org.xnio.conduits.StreamSourceConduit.read.

Read a sequence of bytes from this conduit to the given buffers.

Parameters
dsts:ByteBuffer[]

the buffers to fill with data from the conduit

offs:int

the offset into the buffer array

len:int

the number of buffers to fill

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached or this conduit's terminateReads() method was previously called

Exceptions
IOException:
if an error occurs
resumeReadsback to summary
public void resumeReads()

Overrides org.xnio.conduits.AbstractSourceConduit.resumeReads.

Implements org.xnio.conduits.SourceConduit.resumeReads.

Doc from org.xnio.conduits.SourceConduit.resumeReads.

Indicate that the conduit's ReadReadyHandler should be invoked as soon as data can be read without blocking.

terminateReadsback to summary
public void terminateReads() throws IOException

Overrides org.xnio.conduits.AbstractSourceConduit.terminateReads.

Implements org.xnio.conduits.SourceConduit.terminateReads.

Doc from org.xnio.conduits.SourceConduit.terminateReads.

Indicate that no more data will be read from this conduit. If unread data exists, an exception may be thrown.

Exceptions
IOException:
if there was a problem
transferToback to summary
public long transferTo(long position, long count, final FileChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

Transfers bytes into the given file from this channel.

Parameters
position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

target:FileChannel

the file to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred

Exceptions
IOException:
if an I/O error occurs
transferToback to summary
public long transferTo(final long count, final ByteBuffer throughBuffer, final StreamSinkChannel target) throws IOException

Overrides org.xnio.conduits.AbstractStreamSourceConduit.transferTo.

Implements org.xnio.conduits.StreamSourceConduit.transferTo.

Doc from org.xnio.conduits.StreamSourceConduit.transferTo.

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.

Parameters
count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

target:StreamSinkChannel

the destination to write to

Returns:long

the number of bytes (possibly 0) that were actually transferred, or -1 if the end of input was reached

Exceptions
IOException:
if an I/O error occurs