Package org.apache.sis.io
Class AppendableWriter
java.lang.Object
java.io.Writer
org.apache.sis.io.AppendableWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Wraps a
Appendable
as a Writer
.- Since:
- 0.3
- Version:
- 0.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Appendable
The underlying character output stream or buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new filtered formatter which will send its output to the given stream or buffer. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) Forwards the given single character toout
.append
(CharSequence sequence) Forwards the given character sequence toout
.append
(CharSequence sequence, int start, int end) Forwards the given character sub-sequence toout
.void
close()
void
flush()
private static Object
getLock
(Appendable out) Returns the synchronization lock to use for writing to the givenAppendable
.toString()
Returns the content of the underlyingAppendable
as a string if possible, or the localized "Unavailable content" string otherwise.void
write
(char[] cbuf, int offset, int length) Forwards the given character array toout
.void
write
(int c) Forwards the given single character toout
.void
Forwards the given string toout
.void
Forwards the given sub-string toout
.Methods inherited from class java.io.Writer
nullWriter, write
-
Field Details
-
out
The underlying character output stream or buffer.
-
-
Constructor Details
-
AppendableWriter
AppendableWriter(Appendable out) Creates a new filtered formatter which will send its output to the given stream or buffer.- Parameters:
out
- the underlying character output stream or buffer.
-
-
Method Details
-
getLock
Returns the synchronization lock to use for writing to the givenAppendable
. In particular if the final destination is aStringBuffer
, we want to lock on that buffer since it is already synchronized on itself (so we get only one lock, not two). If the final destination is another writer, we would use itsWriter.lock
field if it wasn't protected... As a fallback we use the writer itself, since writers are often synchronized on themselves. -
append
Forwards the given single character toout
.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
write
Forwards the given single character toout
.- Overrides:
write
in classWriter
- Throws:
IOException
-
append
Forwards the given character sequence toout
.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
write
Forwards the given string toout
.- Overrides:
write
in classWriter
- Throws:
IOException
-
append
Forwards the given character sub-sequence toout
.- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
- Throws:
IOException
-
write
Forwards the given sub-string toout
.- Overrides:
write
in classWriter
- Throws:
IOException
-
write
Forwards the given character array toout
.- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
Ifout
implementsFlushable
, or is aAppender
wrapper around a flushable object, delegates to that object. Otherwise do nothing.- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
Ifout
implementsCloseable
, or is aAppender
wrapper around a closeable object, delegates to that object. Otherwise just flush (if possible).- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
toString
Returns the content of the underlyingAppendable
as a string if possible, or the localized "Unavailable content" string otherwise.
-