Module org.xbib.rpm

Class ChannelWrapper

java.lang.Object
org.xbib.rpm.io.ChannelWrapper
Direct Known Subclasses:
ReadableChannelWrapper, WritableChannelWrapper

public abstract class ChannelWrapper extends Object
Wraps an IO channel so that bytes may be observed during transmission. Wrappers around IO channels are used for a variety of purposes, including counting byte output for use in generating headers, calculating a signature across output bytes, and digesting output bytes using a one-way secure hash.
  • Constructor Details

    • ChannelWrapper

      public ChannelWrapper()
  • Method Details

    • startCount

      public ChannelWrapper.Key<Integer> startCount()
      Initializes a byte counter on this channel.
      Returns:
      reference to the new key added to the consumers
    • startCount

      public ChannelWrapper.Key<byte[]> startCount(ChannelWrapper.Consumer<byte[]> consumer)
      Add a new consumer to this channel.
      Parameters:
      consumer - the channel consumer
      Returns:
      reference to the new key added to the consumers
    • finish

      public <T> T finish(ChannelWrapper.Key<T> object)
    • close

      public void close() throws IOException
      Throws:
      IOException
    • fill

      public static ByteBuffer fill(ReadableByteChannel in, int size) throws IOException
      Creates a new buffer and fills it with bytes from the provided channel. The amount of data to read is specified in the arguments.
      Parameters:
      in - the channel to read from
      size - the number of bytes to read into a new buffer
      Returns:
      a new buffer containing the bytes read
      Throws:
      IOException - if an IO error occurs
    • fill

      public static ByteBuffer fill(ReadableByteChannel in, ByteBuffer buffer) throws IOException
      Fills the provided buffer it with bytes from the provided channel. The amount of data to read is dependant on the available space in the provided buffer.
      Parameters:
      in - the channel to read from
      buffer - the buffer to read into
      Returns:
      the provided buffer
      Throws:
      IOException - if an IO error occurs
    • empty

      public static void empty(WritableByteChannel out, ByteBuffer buffer) throws IOException
      Empties the contents of the given buffer into the writable channel provided. The buffer will be copied to the channel in it's entirety.
      Parameters:
      out - the channel to write to
      buffer - the buffer to write out to the channel
      Throws:
      IOException - if an IO error occurs