public final class LimitWriter extends Writer
If a write call causes the limit to be exceeded and the limit writer is configured to throw an exception, the call will lead to a
LimitExceededException
to be thrown.
Constructor and Description |
---|
LimitWriter(Writer writer,
long limit)
Creates a new limit writer.
|
LimitWriter(Writer writer,
long limit,
LimitExceededStrategy strategy)
Creates a new limit writer.
|
Modifier and Type | Method and Description |
---|---|
Writer |
append(char c) |
Writer |
append(CharSequence csq) |
Writer |
append(CharSequence csq,
int start,
int end) |
void |
close() |
void |
flush() |
void |
write(char[] cbuf,
int off,
int len) |
void |
write(int c) |
void |
write(String str,
int off,
int len) |
public LimitWriter(Writer writer, long limit)
writer
- The writer for which to limit the number of characters that can be written.limit
- The maximum number of characters that can be written.NullPointerException
- If the given writer is null
.IllegalArgumentException
- If the given limit is negative.public LimitWriter(Writer writer, long limit, LimitExceededStrategy strategy)
writer
- The writer for which to limit the number of characters that can be written.limit
- The maximum number of characters that can be written.strategy
- The strategy to follow when the maximum number of characters has exceeded.NullPointerException
- If the given writer or strategy is null
.IllegalArgumentException
- If the given limit is negative.public void write(int c) throws IOException
write
in class Writer
IOException
public void write(char[] cbuf, int off, int len) throws IOException
write
in class Writer
IOException
public void write(String str, int off, int len) throws IOException
write
in class Writer
IOException
public Writer append(CharSequence csq) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public Writer append(CharSequence csq, int start, int end) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public Writer append(char c) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class Writer
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Writer
IOException
Copyright © 2020–2024. All rights reserved.