Interface StreamSinkChannel

All Superinterfaces:
AutoCloseable, Channel, Closeable, CloseableChannel, Configurable, GatheringByteChannel, InterruptibleChannel, SuspendableWriteChannel, WritableByteChannel
All Known Subinterfaces:
ConnectedSslStreamChannel, ConnectedStreamChannel, StreamChannel
All Known Implementing Classes:
AssembledConnectedSslStreamChannel, AssembledConnectedStreamChannel, AssembledStreamChannel, ConduitStreamSinkChannel, FixedLengthStreamSinkChannel, NullStreamSinkChannel, SplitStreamSinkChannel

public interface StreamSinkChannel extends WritableByteChannel, GatheringByteChannel, SuspendableWriteChannel
A stream sink channel. This type of channel is a writable destination for bytes. While all channel types are thread-safe, writing a stream from more than one thread concurrently will cause data corruption and may be disallowed at the option of the implementation.
  • Method Details

    • transferFrom

      long transferFrom(FileChannel src, long position, long count) throws IOException
      Transfer bytes into this channel from the given file. Using this method in preference to FileChannel.transferTo(long, long, WritableByteChannel) may provide a performance advantage on some platforms.

      If the current thread is interrupted when this method is called, it may throw a InterruptedIOException; however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is guaranteed to be 0.

      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

      long transferFrom(StreamSourceChannel source, long count, ByteBuffer throughBuffer) throws IOException
      Transfers bytes from the given channel source. On some platforms, this may avoid copying bytes between user and kernel space. On other platforms, bytes are passed through the throughBuffer parameter's buffer space. 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. Note that using a direct buffer may provide an intermediate performance gain on platforms without zero-copy facilities.

      If the current thread is interrupted when this method is called, it may throw a InterruptedIOException; however, if this exception is thrown, the InterruptedIOException.bytesTransferred field is guaranteed to be 0.

      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
    • getWriteSetter

      ChannelListener.Setter<? extends StreamSinkChannel> getWriteSetter()
      Get the setter which can be used to change the write listener for this channel.
      Specified by:
      getWriteSetter in interface SuspendableWriteChannel
      Returns:
      the setter
    • getCloseSetter

      ChannelListener.Setter<? extends StreamSinkChannel> getCloseSetter()
      Get the setter which can be used to change the close listener for this channel. If the channel is already closed, then the listener will not be called.
      Specified by:
      getCloseSetter in interface CloseableChannel
      Specified by:
      getCloseSetter in interface SuspendableWriteChannel
      Returns:
      the setter
    • writeFinal

      int writeFinal(ByteBuffer src) throws IOException
      Writes some data to the channel, with the same semantics as WritableByteChannel.write(java.nio.ByteBuffer). If all the data is written out then the channel will have its writes shutdown. Semantically this method is equivalent to: int rem = src.remaining(); int written = channel.write(src); if(written == rem) { channel.shutdownWrites() } If an exception is thrown the caller is still responsible for closing the channel.
      Parameters:
      src - The data to write
      Returns:
      The amount of data that was actually written.
      Throws:
      IOException
      See Also:
    • writeFinal

      long writeFinal(ByteBuffer[] srcs, int offset, int length) throws IOException
      Writes some data to the channel, with the same semantics as GatheringByteChannel.write(java.nio.ByteBuffer[], int, int). If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.
      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
      See Also:
    • writeFinal

      long writeFinal(ByteBuffer[] srcs) throws IOException
      Writes some data to the channel, with the same semantics as GatheringByteChannel.write(java.nio.ByteBuffer[]). If all the data is written out then the channel will have its writes shutdown. If an exception is thrown the caller is still responsible for closing the channel.
      Parameters:
      srcs - The buffers from which bytes are to be retrieved
      Returns:
      The amount of data that was actually written
      Throws:
      IOException
      See Also: