Package org.apache.commons.io.output
Class ProxyWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
org.apache.commons.io.output.ProxyWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
CloseShieldWriter
,FileWriterWithEncoding
,TaggedWriter
A Proxy stream which acts as expected, that is it passes the method calls on to the proxied stream and doesn't
change which methods are being called. It is an alternative base class to FilterWriter 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)
.-
Field Summary
Fields inherited from class java.io.FilterWriter
out
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
afterWrite
(int n) Invoked by the write methods after the proxied call has returned successfully.append
(char c) Invokes the delegate'sappend(char)
method.append
(CharSequence csq) Invokes the delegate'sappend(CharSequence)
method.append
(CharSequence csq, int start, int end) Invokes the delegate'sappend(CharSequence, int, int)
method.protected void
beforeWrite
(int n) Invoked by the write methods before the call is proxied.void
close()
Invokes the delegate'sclose()
method.void
flush()
Invokes the delegate'sflush()
method.protected void
Handles any IOExceptions thrown.void
write
(char[] cbuf) Invokes the delegate'swrite(char[])
method.void
write
(char[] cbuf, int off, int len) Invokes the delegate'swrite(char[], int, int)
method.void
write
(int c) Invokes the delegate'swrite(int)
method.void
Invokes the delegate'swrite(String)
method.void
Invokes the delegate'swrite(String)
method.
-
Constructor Details
-
ProxyWriter
Constructs a new ProxyWriter.- Parameters:
proxy
- the Writer to delegate to
-
-
Method Details
-
afterWrite
Invoked by the write methods after the proxied call has returned successfully. The number of chars written (1 for thewrite(int)
method, buffer length forwrite(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.
- Parameters:
n
- number of chars written- Throws:
IOException
- if the post-processing fails- Since:
- 2.0
-
append
Invokes the delegate'sappend(char)
method.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
c
- The character to write- Returns:
- this writer
- Throws:
IOException
- if an I/O error occurs.- Since:
- 2.0
-
append
Invokes the delegate'sappend(CharSequence)
method.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
csq
- The character sequence to write- Returns:
- this writer
- Throws:
IOException
- if an I/O error occurs.- Since:
- 2.0
-
append
Invokes the delegate'sappend(CharSequence, int, int)
method.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
csq
- The character sequence to writestart
- The index of the first character to writeend
- The index of the first character to write (exclusive)- Returns:
- this writer
- Throws:
IOException
- if an I/O error occurs.- Since:
- 2.0
-
beforeWrite
Invoked by the write methods before the call is proxied. The number of chars to be written (1 for thewrite(int)
method, buffer length forwrite(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.
- Parameters:
n
- number of chars to be written- Throws:
IOException
- if the pre-processing fails- Since:
- 2.0
-
close
Invokes the delegate'sclose()
method.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classFilterWriter
- Throws:
IOException
- if an I/O error occurs.
-
flush
Invokes the delegate'sflush()
method.- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterWriter
- Throws:
IOException
- if an I/O error occurs.
-
handleIOException
Handles any IOExceptions thrown.This method provides a point to implement custom exception handling. The default behavior is to re-throw the exception.
- Parameters:
e
- The IOException thrown- Throws:
IOException
- if an I/O error occurs.- Since:
- 2.0
-
write
Invokes the delegate'swrite(char[])
method.- Overrides:
write
in classWriter
- Parameters:
cbuf
- the characters to write- Throws:
IOException
- if an I/O error occurs.
-
write
Invokes the delegate'swrite(char[], int, int)
method.- Overrides:
write
in classFilterWriter
- Parameters:
cbuf
- the characters to writeoff
- The start offsetlen
- The number of characters to write- Throws:
IOException
- if an I/O error occurs.
-
write
Invokes the delegate'swrite(int)
method.- Overrides:
write
in classFilterWriter
- Parameters:
c
- the character to write- Throws:
IOException
- if an I/O error occurs.
-
write
Invokes the delegate'swrite(String)
method.- Overrides:
write
in classWriter
- Parameters:
str
- the string to write- Throws:
IOException
- if an I/O error occurs.
-
write
Invokes the delegate'swrite(String)
method.- Overrides:
write
in classFilterWriter
- Parameters:
str
- the string to writeoff
- The start offsetlen
- The number of characters to write- Throws:
IOException
- if an I/O error occurs.
-