public final class LimitOutputStream extends OutputStream
If a write call causes the limit to be exceeded and the limit output stream is configured to throw an exception, the call will lead to a
LimitExceededException
to be thrown.
Constructor and Description |
---|
LimitOutputStream(OutputStream output,
long limit)
Creates a new limit output stream.
|
LimitOutputStream(OutputStream output,
long limit,
LimitExceededStrategy strategy)
Creates a new limit output stream.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
void |
flush() |
void |
write(byte[] b,
int off,
int len) |
void |
write(int c) |
write
public LimitOutputStream(OutputStream output, long limit)
output
- The output stream for which to limit the number of bytes that can be written.limit
- The maximum number of bytes that can be written.NullPointerException
- If the given output stream is null
.IllegalArgumentException
- If the given limit is negative.public LimitOutputStream(OutputStream output, long limit, LimitExceededStrategy strategy)
output
- The output stream for which to limit the number of bytes that can be written.limit
- The maximum number of bytes that can be written.strategy
- The strategy to follow when the maximum number of bytes has exceeded.NullPointerException
- If the given output stream or strategy is null
.IllegalArgumentException
- If the given limit is negative.public void write(int c) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
Copyright © 2020–2024. All rights reserved.