Package org.apache.commons.io.output
Class AppendableWriter<T extends java.lang.Appendable>
- java.lang.Object
-
- java.io.Writer
-
- org.apache.commons.io.output.AppendableWriter<T>
-
- Type Parameters:
T- The type of theAppendablewrapped by this AppendableWriter.
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class AppendableWriter<T extends java.lang.Appendable> extends java.io.WriterWriter implementation that writes the data to anAppendableObject.For example, can be used with a
StringBuilderorStringBuffer.- Since:
- 2.7
- See Also:
Appendable
-
-
Constructor Summary
Constructors Constructor Description AppendableWriter(T appendable)Constructs a new instance with the specified appendable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.io.Writerappend(char c)Appends the specified character to the underlying appendable.java.io.Writerappend(java.lang.CharSequence csq)Appends the specified character sequence to the underlying appendable.java.io.Writerappend(java.lang.CharSequence csq, int start, int end)Appends a subsequence of the specified character sequence to the underlying appendable.voidclose()Closes the stream.voidflush()Flushes the stream.TgetAppendable()Gets the target appendable.voidwrite(char[] cbuf, int off, int len)Writes a portion of an array of characters to the underlying appendable.voidwrite(int c)Writes a character to the underlying appendable.voidwrite(java.lang.String str, int off, int len)Writes a portion of a String to the underlying appendable.
-
-
-
Constructor Detail
-
AppendableWriter
public AppendableWriter(T appendable)
Constructs a new instance with the specified appendable.- Parameters:
appendable- the appendable to write to
-
-
Method Detail
-
append
public java.io.Writer append(char c) throws java.io.IOExceptionAppends the specified character to the underlying appendable.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- Parameters:
c- the character to append- Returns:
- this writer
- Throws:
java.io.IOException- upon error
-
append
public java.io.Writer append(java.lang.CharSequence csq) throws java.io.IOExceptionAppends the specified character sequence to the underlying appendable.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- Parameters:
csq- the character sequence to append- Returns:
- this writer
- Throws:
java.io.IOException- upon error
-
append
public java.io.Writer append(java.lang.CharSequence csq, int start, int end) throws java.io.IOExceptionAppends a subsequence of the specified character sequence to the underlying appendable.- Specified by:
appendin interfacejava.lang.Appendable- Overrides:
appendin classjava.io.Writer- Parameters:
csq- the character sequence from which a subsequence will be appendedstart- the index of the first character in the subsequenceend- the index of the character following the last character in the subsequence- Returns:
- this writer
- Throws:
java.io.IOException- upon error
-
close
public void close() throws java.io.IOExceptionCloses the stream. This implementation does nothing.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException- upon error
-
flush
public void flush() throws java.io.IOExceptionFlushes the stream. This implementation does nothing.- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException- upon error
-
getAppendable
public T getAppendable()
Gets the target appendable.- Returns:
- the target appendable
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrites a portion of an array of characters to the underlying appendable.- Specified by:
writein classjava.io.Writer- Parameters:
cbuf- an array with the characters to writeoff- offset from which to start writing characterslen- number of characters to write- Throws:
java.io.IOException- upon error
-
write
public void write(int c) throws java.io.IOExceptionWrites a character to the underlying appendable.- Overrides:
writein classjava.io.Writer- Parameters:
c- the character to write- Throws:
java.io.IOException- upon error
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOExceptionWrites a portion of a String to the underlying appendable.- Overrides:
writein classjava.io.Writer- Parameters:
str- a stringoff- offset from which to start writing characterslen- number of characters to write- Throws:
java.io.IOException- upon error
-
-