Top Description Fields Constructors Methods
io.undertow.conduits

public final Class HeadStreamSinkConduit

extends AbstractStreamSinkConduit<StreamSinkConduit>
Class Inheritance
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.ClosedChannelException, .FileChannel, org.xnio.IoUtils, org.xnio.channels.StreamSourceChannel, org.xnio.conduits.AbstractStreamSinkConduit, .ConduitWritableByteChannel, .Conduits, .StreamSinkConduit

A conduit that discards all data written to it. This allows head requests to 'just work', as all data written will be discarded.
Author
Stuart Douglas

Field Summary

Modifier and TypeField and Description
private final ConduitListener<? super HeadStreamSinkConduit>
private static final int
private static final int
private static final int
private final boolean
private int

Constructor Summary

AccessConstructor and Description
public
HeadStreamSinkConduit(final StreamSinkConduit
the next channel
next
,
final ConduitListener<? super HeadStreamSinkConduit>
the listener to call when the channel is closed or the length is reached
finishListener
)

Construct a new instance.

public
HeadStreamSinkConduit(final StreamSinkConduit
the next channel
next
,
final ConduitListener<? super HeadStreamSinkConduit>
the listener to call when the channel is closed or the length is reached
finishListener
,
boolean shutdownDelegate)

Construct a new instance.

Method Summary

Modifier and TypeMethod and Description
private void
exitFlush(int oldVal, boolean flushed)

public boolean
flush()

Overrides org.xnio.conduits.AbstractSinkConduit.flush.

Implements org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

public boolean
isWriteResumed()

Overrides org.xnio.conduits.AbstractSinkConduit.isWriteResumed.

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

public void
resumeWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.resumeWrites.

Implements org.xnio.conduits.SinkConduit.resumeWrites.

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

public void
suspendWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.suspendWrites.

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

public void
public long
transferFrom(final FileChannel
the file to read from
src
,
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
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

public long
transferFrom(final StreamSourceChannel
the source to read from
source
,
final long
the number of bytes to be transferred
count
,
final ByteBuffer
the buffer to copy through.
throughBuffer
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfers bytes from the given channel source.

public void
wakeupWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.wakeupWrites.

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

public int
write(final ByteBuffer
the buffer containing data to write
src
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

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

public long
write(final ByteBuffer[]
the buffers containing data to write
srcs
,
final int
the offset into the buffer array
offset
,
final int
the number of buffers to write
length
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

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

public int
writeFinal(ByteBuffer
The data to write
src
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer).

public long
writeFinal(ByteBuffer[]
The buffers from which bytes are to be retrieved
srcs
,
int
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
offset
,
int
The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset
length
)

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int).

Field Detail

finishListenerback to summary
private final ConduitListener<? super HeadStreamSinkConduit> finishListener
FLAG_CLOSE_COMPLETEback to summary
private static final int FLAG_CLOSE_COMPLETE
FLAG_CLOSE_REQUESTEDback to summary
private static final int FLAG_CLOSE_REQUESTED
FLAG_FINISHED_CALLEDback to summary
private static final int FLAG_FINISHED_CALLED
shutdownDelegateback to summary
private final boolean shutdownDelegate
stateback to summary
private int state

Constructor Detail

HeadStreamSinkConduitback to summary
public HeadStreamSinkConduit(final StreamSinkConduit next, final ConduitListener<? super HeadStreamSinkConduit> finishListener)

Construct a new instance.

Parameters
next:StreamSinkConduit

the next channel

finishListener:ConduitListener<? super HeadStreamSinkConduit>

the listener to call when the channel is closed or the length is reached

HeadStreamSinkConduitback to summary
public HeadStreamSinkConduit(final StreamSinkConduit next, final ConduitListener<? super HeadStreamSinkConduit> finishListener, boolean shutdownDelegate)

Construct a new instance.

Parameters
next:StreamSinkConduit

the next channel

finishListener:ConduitListener<? super HeadStreamSinkConduit>

the listener to call when the channel is closed or the length is reached

Method Detail

exitFlushback to summary
private void exitFlush(int oldVal, boolean flushed)
flushback to summary
public boolean flush() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.flush.

Implements org.xnio.conduits.SinkConduit.flush.

Doc from org.xnio.conduits.SinkConduit.flush.

Flush out any unwritten, buffered output.

Returns:boolean

true if everything is flushed, false otherwise

Exceptions
IOException:
if flush fails
isWriteResumedback to summary
public boolean isWriteResumed()

Overrides org.xnio.conduits.AbstractSinkConduit.isWriteResumed.

Implements org.xnio.conduits.SinkConduit.isWriteResumed.

Doc from org.xnio.conduits.SinkConduit.isWriteResumed.

Determine whether write notifications are currently enabled.

Returns:boolean

true if write notifications are enabled

resumeWritesback to summary
public void resumeWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.resumeWrites.

Implements org.xnio.conduits.SinkConduit.resumeWrites.

Doc from org.xnio.conduits.SinkConduit.resumeWrites.

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

suspendWritesback to summary
public void suspendWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.suspendWrites.

Implements org.xnio.conduits.SinkConduit.suspendWrites.

Doc from org.xnio.conduits.SinkConduit.suspendWrites.

Indicate that calling the conduit's WriteReadyHandler should be suspended.

terminateWritesback to summary
public void terminateWrites() throws IOException

Overrides org.xnio.conduits.AbstractSinkConduit.terminateWrites.

Implements org.xnio.conduits.SinkConduit.terminateWrites.

Doc from org.xnio.conduits.SinkConduit.terminateWrites.

Signal that no more write data is forthcoming. The conduit must be flush()ed before it is considered to be shut down.

transferFromback to summary
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

Transfer bytes into this conduit from the given file.

Parameters
src:FileChannel

the file to read from

position:long

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

count:long

the number of bytes to be transferred

Returns:long

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
transferFromback to summary
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.transferFrom.

Implements org.xnio.conduits.StreamSinkConduit.transferFrom.

Doc from org.xnio.conduits.StreamSinkConduit.transferFrom.

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.

Parameters
source:StreamSourceChannel

the source to read from

count:long

the number of bytes to be transferred

throughBuffer:ByteBuffer

the buffer to copy through.

Returns:long

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
wakeupWritesback to summary
public void wakeupWrites()

Overrides org.xnio.conduits.AbstractSinkConduit.wakeupWrites.

Implements org.xnio.conduits.SinkConduit.wakeupWrites.

Doc from org.xnio.conduits.SinkConduit.wakeupWrites.

Indicate that the conduit's WriteReadyHandler should be invoked immediately, and then again as soon as data can be written without blocking.

writeback to summary
public int write(final ByteBuffer src) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

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

Parameters
src:ByteBuffer

the buffer containing data to write

Returns:int

the number of bytes written, possibly 0

Exceptions
IOException:
if an error occurs
writeback to summary
public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.write.

Implements org.xnio.conduits.StreamSinkConduit.write.

Doc from org.xnio.conduits.StreamSinkConduit.write.

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

Parameters
srcs:ByteBuffer[]

the buffers containing data to write

offset:int

the offset into the buffer array

length:int

the number of buffers to write

Returns:long

the number of bytes written, possibly 0

Exceptions
IOException:
if an error occurs
writeFinalback to summary
public int writeFinal(ByteBuffer src) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as 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() }

Parameters
src:ByteBuffer

The data to write

Returns:int

The amount of data that was actually written.

Annotations
@Override
writeFinalback to summary
public long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException

Overrides org.xnio.conduits.AbstractStreamSinkConduit.writeFinal.

Implements org.xnio.conduits.StreamSinkConduit.writeFinal.

Doc from org.xnio.conduits.StreamSinkConduit.writeFinal.

Writes some data to the conduit, with the same semantics as write(java.nio.ByteBuffer[], int, int). If all the data is written out then the conduit will have its writes terminated.

Parameters
srcs:ByteBuffer[]

The buffers from which bytes are to be retrieved

offset:int

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:int

The maximum number of buffers to be accessed; must be non-negative and no larger than srcs.length - offset

Returns:long

The amount of data that was actually written

Annotations
@Override