Package com.unboundid.util
Class RateLimitedOutputStream
java.lang.Object
java.io.OutputStream
com.unboundid.util.RateLimitedOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
This class provides an
OutputStream implementation that uses a
FixedRateBarrier to impose an upper bound on the rate (in bytes per
second) at which data can be written to a wrapped OutputStream.-
Constructor Summary
ConstructorsConstructorDescriptionRateLimitedOutputStream(OutputStream wrappedStream, int maxBytesPerSecond, boolean autoFlush) Creates a new instance of this rate-limited output stream that wraps the provided output stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this output stream and the wrapped stream.voidflush()Flushes the contents of the wrapped stream.voidwrite(byte[] b) Writes the contents of the provided array to the wrapped output stream.voidwrite(byte[] b, int offset, int length) Writes the contents of the specified portion of the provided array to the wrapped output stream.voidwrite(int b) Writes a single byte of data to the wrapped output stream.Methods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
RateLimitedOutputStream
public RateLimitedOutputStream(@NotNull OutputStream wrappedStream, int maxBytesPerSecond, boolean autoFlush) Creates a new instance of this rate-limited output stream that wraps the provided output stream.- Parameters:
wrappedStream- The output stream to which the data will actually be written. It must not benull.maxBytesPerSecond- The maximum number of bytes per second that can be written using this output stream. It must be greater than zero.autoFlush- Indicates whether to automatically flush the wrapped output stream after each write.
-
-
Method Details
-
close
Closes this output stream and the wrapped stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException- If a problem is encountered while closing the wrapped output stream.
-
write
Writes a single byte of data to the wrapped output stream.- Specified by:
writein classOutputStream- Parameters:
b- The byte of data to be written. Only the least significant eight bits will be written.- Throws:
IOException- If a problem is encountered while writing to the wrapped stream.
-
write
Writes the contents of the provided array to the wrapped output stream.- Overrides:
writein classOutputStream- Parameters:
b- The byte array containing the data to be written. It must not benull.- Throws:
IOException- If a problem is encountered while writing to the wrapped stream.
-
write
Writes the contents of the specified portion of the provided array to the wrapped output stream.- Overrides:
writein classOutputStream- Parameters:
b- The byte array containing the data to be written. It must not benull.offset- The position in the provided array at which the data to write begins. It must be greater than or equal to zero and less than the length of the provided array.length- The number of bytes to be written. It must not be negative, and the sum of offset and length must be less than or equal to the length of the provided array.- Throws:
IOException- If a problem is encountered while writing to the wrapped stream.
-
flush
Flushes the contents of the wrapped stream.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException- If a problem is encountered while flushing the wrapped stream.
-