java.lang.Object
edu.iu.IuFixedLimitOutputBuffer
Maintains a fixed buffer of streamed data, for normalizing the rate of output
and limiting output to a single source.
-
Constructor Summary
ConstructorsConstructorDescriptionIuFixedLimitOutputBuffer
(int bufferSize, long count, long maxSize) Constructor.IuFixedLimitOutputBuffer
(long maxSize) Constructor.IuFixedLimitOutputBuffer
(long count, long maxSize) Constructor. -
Method Summary
Modifier and TypeMethodDescription(package private) int
Gets the number of bytes available in the buffer.boolean
Fills the buffer with source data.int
Gets the number of bytes remaining in the target output quota.void
Resets the count of bytes written to the target.void
write
(Supplier<byte[]> dataSupplier, OutputStream out) Writes to anOutputStream
, as long as it source data is available, up to themax size
.
-
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 targetmaxSize
- 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 sizecount
- number of bytes previously written to the targetmaxSize
- 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
Writes to anOutputStream
, as long as it source data is available, up to themax size
.This method returns when:
dataSupplier.get()
returns null to indicate no more source data is available.- The
max size
has been reached.remaining()
will return 0 and no more data will be written from this buffer without first invokingresetCount()
.
- Parameters:
dataSupplier
-Supplier
of source dataout
-OutputStream
- Throws:
IOException
- If an error occurs writing to the stream.
-
fill
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.
-