public class ProxyCollectionWriter extends FilterCollectionWriter
FilterWriter
and
FilterCollectionWriter
to increase reusability, because FilterWriter changes the methods being called, such
as write(char[])
to write(char[], int, int)
and write(String)
to
write(String, int, int)
. This is in contrast to ProxyWriter
which is backed by a single
Writer
.EMPTY_WRITERS, writers
Constructor and Description |
---|
ProxyCollectionWriter(Collection<Writer> writers)
Creates a new proxy collection writer.
|
ProxyCollectionWriter(Writer... writers)
Creates a new proxy collection writer.
|
Modifier and Type | Method and Description |
---|---|
protected void |
afterWrite(int n)
Invoked by the write methods after the proxied call has returned successfully.
|
Writer |
append(char c)
Invokes the delegates'
append(char) methods. |
Writer |
append(CharSequence csq)
Invokes the delegates'
append(CharSequence) methods. |
Writer |
append(CharSequence csq,
int start,
int end)
Invokes the delegates'
append(CharSequence, int, int) methods. |
protected void |
beforeWrite(int n)
Invoked by the write methods before the call is proxied.
|
void |
close()
Invokes the delegate's
close() method. |
void |
flush()
Invokes the delegate's
flush() method. |
protected void |
handleIOException(IOException e)
Handle any IOExceptions thrown.
|
void |
write(char[] cbuf)
Invokes the delegate's
write(char[]) method. |
void |
write(char[] cbuf,
int off,
int len)
Invokes the delegate's
write(char[], int, int) method. |
void |
write(int c)
Invokes the delegate's
write(int) method. |
void |
write(String str)
Invokes the delegate's
write(String) method. |
void |
write(String str,
int off,
int len)
Invokes the delegate's
write(String) method. |
public ProxyCollectionWriter(Collection<Writer> writers)
writers
- Writers object to provide the underlying targets.public ProxyCollectionWriter(Writer... writers)
writers
- Writers to provide the underlying targets.protected void afterWrite(int n) throws IOException
write(int)
method, buffer length for write(char[])
, etc.) is given as an argument.
Subclasses can override this method to add common post-processing functionality without having to override all the write methods. The default implementation does nothing.
n
- number of chars writtenIOException
- if the post-processing failspublic Writer append(char c) throws IOException
append(char)
methods.append
in interface Appendable
append
in class FilterCollectionWriter
c
- The character to writeIOException
- if an I/O error occurspublic Writer append(CharSequence csq) throws IOException
append(CharSequence)
methods.append
in interface Appendable
append
in class FilterCollectionWriter
csq
- The character sequence to writeIOException
- if an I/O error occurspublic Writer append(CharSequence csq, int start, int end) throws IOException
append(CharSequence, int, int)
methods.append
in interface Appendable
append
in class FilterCollectionWriter
csq
- The character sequence to writestart
- The index of the first character to writeend
- The index of the first character to write (exclusive)IOException
- if an I/O error occursprotected void beforeWrite(int n) throws IOException
write(int)
method, buffer length for write(char[])
, etc.) is given as an argument.
Subclasses can override this method to add common pre-processing functionality without having to override all the write methods. The default implementation does nothing.
n
- number of chars to be writtenIOException
- if the pre-processing failspublic void close() throws IOException
close()
method.close
in interface Closeable
close
in interface AutoCloseable
close
in class FilterCollectionWriter
IOException
- if an I/O error occurspublic void flush() throws IOException
flush()
method.flush
in interface Flushable
flush
in class FilterCollectionWriter
IOException
- if an I/O error occursprotected void handleIOException(IOException e) throws IOException
This method provides a point to implement custom exception handling. The default behavior is to re-throw the exception.
e
- The IOException thrownIOException
- if an I/O error occurspublic void write(char[] cbuf) throws IOException
write(char[])
method.write
in class FilterCollectionWriter
cbuf
- the characters to writeIOException
- if an I/O error occurspublic void write(char[] cbuf, int off, int len) throws IOException
write(char[], int, int)
method.write
in class FilterCollectionWriter
cbuf
- the characters to writeoff
- The start offsetlen
- The number of characters to writeIOException
- if an I/O error occurspublic void write(int c) throws IOException
write(int)
method.write
in class FilterCollectionWriter
c
- the character to writeIOException
- if an I/O error occurspublic void write(String str) throws IOException
write(String)
method.write
in class FilterCollectionWriter
str
- the string to writeIOException
- if an I/O error occurspublic void write(String str, int off, int len) throws IOException
write(String)
method.write
in class FilterCollectionWriter
str
- the string to writeoff
- The start offsetlen
- The number of characters to writeIOException
- if an I/O error occursCopyright © 2002–2020 The Apache Software Foundation. All rights reserved.