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:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
- Direct Known Subclasses:
CloseShieldWriter,TaggedWriter
public class ProxyWriter extends java.io.FilterWriterA 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 aswrite(char[]) to write(char[], int, int)andwrite(String) to write(String, int, int).
-
-
Constructor Summary
Constructors Constructor Description ProxyWriter(java.io.Writer proxy)Constructs a new ProxyWriter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafterWrite(int n)Invoked by the write methods after the proxied call has returned successfully.java.io.Writerappend(char c)Invokes the delegate'sappend(char)method.java.io.Writerappend(java.lang.CharSequence csq)Invokes the delegate'sappend(CharSequence)method.java.io.Writerappend(java.lang.CharSequence csq, int start, int end)Invokes the delegate'sappend(CharSequence, int, int)method.protected voidbeforeWrite(int n)Invoked by the write methods before the call is proxied.voidclose()Invokes the delegate'sclose()method.voidflush()Invokes the delegate'sflush()method.protected voidhandleIOException(java.io.IOException e)Handle any IOExceptions thrown.voidwrite(char[] cbuf)Invokes the delegate'swrite(char[])method.voidwrite(char[] cbuf, int off, int len)Invokes the delegate'swrite(char[], int, int)method.voidwrite(int c)Invokes the delegate'swrite(int)method.voidwrite(java.lang.String str)Invokes the delegate'swrite(String)method.voidwrite(java.lang.String str, int off, int len)Invokes the delegate'swrite(String)method.
-
-
-
Method Detail
-
append
public java.io.Writer append(char c) throws java.io.IOExceptionInvokes the delegate'sappend(char)method.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- Parameters:
c- The character to write- Returns:
- this writer
- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- 2.0
-
append
public java.io.Writer append(java.lang.CharSequence csq, int start, int end) throws java.io.IOExceptionInvokes the delegate'sappend(CharSequence, int, int)method.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- 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:
java.io.IOException- if an I/O error occurs.- Since:
- 2.0
-
append
public java.io.Writer append(java.lang.CharSequence csq) throws java.io.IOExceptionInvokes the delegate'sappend(CharSequence)method.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- Parameters:
csq- The character sequence to write- Returns:
- this writer
- Throws:
java.io.IOException- if an I/O error occurs.- Since:
- 2.0
-
write
public void write(int c) throws java.io.IOExceptionInvokes the delegate'swrite(int)method.- Overrides:
writein classjava.io.FilterWriter- Parameters:
c- the character to write- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(char[] cbuf) throws java.io.IOExceptionInvokes the delegate'swrite(char[])method.- Overrides:
writein classjava.io.Writer- Parameters:
cbuf- the characters to write- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionInvokes the delegate'swrite(char[], int, int)method.- Overrides:
writein classjava.io.FilterWriter- Parameters:
cbuf- the characters to writeoff- The start offsetlen- The number of characters to write- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(java.lang.String str) throws java.io.IOExceptionInvokes the delegate'swrite(String)method.- Overrides:
writein classjava.io.Writer- Parameters:
str- the string to write- Throws:
java.io.IOException- if an I/O error occurs.
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOExceptionInvokes the delegate'swrite(String)method.- Overrides:
writein classjava.io.FilterWriter- Parameters:
str- the string to writeoff- The start offsetlen- The number of characters to write- Throws:
java.io.IOException- if an I/O error occurs.
-
flush
public void flush() throws java.io.IOExceptionInvokes the delegate'sflush()method.- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.FilterWriter- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOExceptionInvokes the delegate'sclose()method.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterWriter- Throws:
java.io.IOException- if an I/O error occurs.
-
beforeWrite
protected void beforeWrite(int n) throws java.io.IOExceptionInvoked 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:
java.io.IOException- if the pre-processing fails- Since:
- 2.0
-
afterWrite
protected void afterWrite(int n) throws java.io.IOExceptionInvoked 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:
java.io.IOException- if the post-processing fails- Since:
- 2.0
-
handleIOException
protected void handleIOException(java.io.IOException e) throws java.io.IOExceptionHandle 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:
java.io.IOException- if an I/O error occurs.- Since:
- 2.0
-
-