Package org.apache.commons.io.output
Class AppendableWriter<T extends Appendable>
java.lang.Object
java.io.Writer
org.apache.commons.io.output.AppendableWriter<T>
- Type Parameters:
T
- The type of theAppendable
wrapped by this AppendableWriter.
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Writer implementation that writes the data to an
Appendable
Object.
For example, can be used with a StringBuilder
or StringBuffer
.
- Since:
- 2.7
- See Also:
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAppendableWriter
(T appendable) Constructs a new instance with the specified appendable. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) Appends the specified character to the underlying appendable.append
(CharSequence csq) Appends the specified character sequence to the underlying appendable.append
(CharSequence csq, int start, int end) Appends a subsequence of the specified character sequence to the underlying appendable.void
close()
Closes the stream.void
flush()
Flushes the stream.Gets the target appendable.void
write
(char[] cbuf, int off, int len) Writes a portion of an array of characters to the underlying appendable.void
write
(int c) Writes a character to the underlying appendable.void
Writes a portion of a String to the underlying appendable.
-
Constructor Details
-
AppendableWriter
Constructs a new instance with the specified appendable.- Parameters:
appendable
- the appendable to write to
-
-
Method Details
-
append
Appends the specified character to the underlying appendable.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
c
- the character to append- Returns:
- this writer
- Throws:
IOException
- upon error
-
append
Appends the specified character sequence to the underlying appendable.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Parameters:
csq
- the character sequence to append- Returns:
- this writer
- Throws:
IOException
- upon error
-
append
Appends a subsequence of the specified character sequence to the underlying appendable.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- 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:
IOException
- upon error
-
close
Closes the stream. This implementation does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
- upon error
-
flush
Flushes the stream. This implementation does nothing.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
- upon error
-
getAppendable
Gets the target appendable.- Returns:
- the target appendable
-
write
Writes a portion of an array of characters to the underlying appendable.- Specified by:
write
in classWriter
- Parameters:
cbuf
- an array with the characters to writeoff
- offset from which to start writing characterslen
- number of characters to write- Throws:
IOException
- upon error
-
write
Writes a character to the underlying appendable.- Overrides:
write
in classWriter
- Parameters:
c
- the character to write- Throws:
IOException
- upon error
-
write
Writes a portion of a String to the underlying appendable.- Overrides:
write
in classWriter
- Parameters:
str
- a stringoff
- offset from which to start writing characterslen
- number of characters to write- Throws:
IOException
- upon error
-