Module iu.util
Package edu.iu

Class IuFixedLimitOutputBuffer

java.lang.Object
edu.iu.IuFixedLimitOutputBuffer

public class IuFixedLimitOutputBuffer extends Object
Maintains a fixed buffer of streamed data, for normalizing the rate of output and limiting output to a single source.
  • Constructor Details

    • IuFixedLimitOutputBuffer

      public IuFixedLimitOutputBuffer(long maxSize)
      Constructor.
      Parameters:
      maxSize - maximum number of bytes to allow writing to the target
    • IuFixedLimitOutputBuffer

      public IuFixedLimitOutputBuffer(long count, long maxSize)
      Constructor.
      Parameters:
      count - number of bytes previously written to the target
      maxSize - maximum number of bytes to allow writing to the target
    • IuFixedLimitOutputBuffer

      public IuFixedLimitOutputBuffer(int bufferSize, long count, long maxSize)
      Constructor.
      Parameters:
      bufferSize - fixed length buffer size
      count - number of bytes previously written to the target
      maxSize - maximum number of bytes to allow writing to the target
  • Method Details

    • resetCount

      public void resetCount()
      Resets the count of bytes written to the target.
    • remaining

      public int remaining()
      Gets the number of bytes remaining in the target output quota.
      Returns:
      number of bytes remaining in the target output quota.
    • write

      public void write(Supplier<byte[]> dataSupplier, OutputStream out) throws IOException
      Writes to an OutputStream, as long as it source data is available, up to the max size.

      This method returns when:

      Parameters:
      dataSupplier - Supplier of source data
      out - OutputStream
      Throws:
      IOException - If an error occurs writing to the stream.
    • fill

      public boolean fill(Supplier<byte[]> dataSupplier)
      Fills the buffer with source data.
      Parameters:
      dataSupplier - Supplier of source data
      Returns:
      true if data was added to the buffer; else false
    • available

      int available()
      Gets the number of bytes available in the buffer.
      Returns:
      number of bytes available in the buffer.