java.lang.Object | |
↳ | java.io.Writer |
Known Direct Subclasses |
Known Indirect Subclasses |
The base class for all writers. A writer is a means of writing data to a
target in a character-wise manner. Most output streams expect the
flush()
method to be called before closing the stream, to ensure all
data is actually written out.
This abstract class does not provide a fully working implementation, so it
needs to be subclassed, and at least the write(char[], int, int)
,
close()
and flush()
methods needs to be overridden.
Overriding some of the non-abstract methods is also often advised, since it
might result in higher efficiency.
Many specialized readers for purposes like reading from a file already exist in this package.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
lock | The object used to synchronize access to the writer. |
Protected Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
Writer with this as the object used to
synchronize critical sections.
| |||||||||||
Constructs a new
Writer with lock used to synchronize
critical sections.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends the character sequence
csq to the target.
| |||||||||||
Appends a subsequence of the character sequence
csq to the
target.
| |||||||||||
Appends the character
c to the target.
| |||||||||||
Closes this writer.
| |||||||||||
Flushes this writer.
| |||||||||||
Writes the entire character buffer
buf to the target.
| |||||||||||
Writes the characters from the specified string to the target.
| |||||||||||
Writes
count characters starting at offset in buf
to the target.
| |||||||||||
Writes
count characters from str starting at offset to the target.
| |||||||||||
Writes one character to the target.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.lang.Appendable
| |||||||||||
From interface
java.io.Closeable
| |||||||||||
From interface
java.io.Flushable
| |||||||||||
From interface
java.lang.AutoCloseable
|
Constructs a new Writer
with this
as the object used to
synchronize critical sections.
Constructs a new Writer
with lock
used to synchronize
critical sections.
lock | the Object used to synchronize critical sections. |
---|
NullPointerException | if lock is null .
|
---|
Appends the character sequence csq
to the target. This method
works the same way as Writer.write(csq.toString())
. If csq
is null
, then the string "null" is written to the target
stream.
csq | the character sequence appended to the target. |
---|
IOException | if this writer is closed or another I/O error occurs. |
---|
Appends a subsequence of the character sequence csq
to the
target. This method works the same way as Writer.writer(csq.subsequence(start, end).toString())
. If csq
is null
, then the specified subsequence of the string "null"
will be written to the target.
csq | the character sequence appended to the target. |
---|---|
start | the index of the first char in the character sequence appended to the target. |
end | the index of the character following the last character of the subsequence appended to the target. |
IOException | if this writer is closed or another I/O error occurs. |
---|---|
IndexOutOfBoundsException | if start > end , start < 0 , end < 0 or
either start or end are greater or equal than
the length of csq .
|
Appends the character c
to the target. This method works the same
way as write(int)
.
c | the character to append to the target stream. |
---|
IOException | if this writer is closed or another I/O error occurs. |
---|
Closes this writer. Implementations of this method should free any resources associated with the writer.
IOException | if an error occurs while closing this writer. |
---|
Flushes this writer. Implementations of this method should ensure that all buffered characters are written to the target.
IOException | if an error occurs while flushing this writer. |
---|
Writes the entire character buffer buf
to the target.
buf | the non-null array containing characters to write. |
---|
IOException | if this writer is closed or another I/O error occurs. |
---|
Writes the characters from the specified string to the target.
str | the non-null string containing the characters to write. |
---|
IOException | if this writer is closed or another I/O error occurs. |
---|
Writes count
characters starting at offset
in buf
to the target.
buf | the non-null character array to write. |
---|---|
offset | the index of the first character in buf to write. |
count | the maximum number of characters to write. |
IndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is greater than the size of buf . |
---|---|
IOException | if this writer is closed or another I/O error occurs. |
Writes count
characters from str
starting at offset
to the target.
str | the non-null string containing the characters to write. |
---|---|
offset | the index of the first character in str to write. |
count | the number of characters from str to write. |
IOException | if this writer is closed or another I/O error occurs. |
---|---|
IndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is greater than the length of str .
|
Writes one character to the target. Only the two least significant bytes
of the integer oneChar
are written.
oneChar | the character to write to the target. |
---|
IOException | if this writer is closed or another I/O error occurs. |
---|