Known Direct Subclasses
| BufferedWriter |
Wraps an existing Writer and buffers the output.
|
| CharArrayWriter |
A specialized Writer for class for writing content to an (internal)
char array.
|
| FilterWriter |
Wraps an existing Writer and performs some transformation on the
output data while it is being written.
|
| OutputStreamWriter |
A class for turning a character stream into a byte stream.
|
| PipedWriter |
Places information on a communications pipe.
|
| PrintWriter |
Wraps either an existing OutputStream or an existing Writer
and provides convenience methods for printing common data types in a human
readable format.
|
| StringWriter |
A specialized Writer that writes characters to a StringBuffer
in a sequential manner, appending them in the process.
|
|
Known Indirect Subclasses
|
Class Overview
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.
Summary
| Fields |
|
protected
Object |
lock |
The object used to synchronize access to the writer.
|
| Protected Constructors |
|
|
Writer()
Constructs a new Writer with this as the object used to
synchronize critical sections.
|
|
|
Writer(Object lock)
Constructs a new Writer with lock used to synchronize
critical sections.
|
| Public Methods |
|
Writer
|
append(CharSequence csq)
Appends the character sequence csq to the target.
|
|
Writer
|
append(CharSequence csq, int start, int end)
Appends a subsequence of the character sequence csq to the
target.
|
|
Writer
|
append(char c)
Appends the character c to the target.
|
|
abstract
void
|
close()
Closes this writer.
|
|
abstract
void
|
flush()
Flushes this writer.
|
|
void
|
write(char[] buf)
Writes the entire character buffer buf to the target.
|
|
void
|
write(String str)
Writes the characters from the specified string to the target.
|
|
abstract
void
|
write(char[] buf, int offset, int count)
Writes count characters starting at offset in buf
to the target.
|
|
void
|
write(String str, int offset, int count)
Writes count characters from str starting at offset to the target.
|
|
void
|
write(int oneChar)
Writes one character to the target.
|
|
[Expand]
Inherited Methods |
From class
java.lang.Object
|
Object
|
clone()
Creates and returns a copy of this Object.
|
|
boolean
|
equals(Object o)
Compares this instance with the specified object and indicates if they
are equal.
|
|
void
|
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
|
final
Class<?>
|
getClass()
Returns the unique instance of Class that represents this
object's class.
|
|
int
|
hashCode()
Returns an integer hash code for this object.
|
|
final
void
|
notify()
Causes a thread which is waiting on this object's monitor (by means of
calling one of the wait() methods) to be woken up.
|
|
final
void
|
notifyAll()
Causes all threads which are waiting on this object's monitor (by means
of calling one of the wait() methods) to be woken up.
|
|
String
|
toString()
Returns a string containing a concise, human-readable description of this
object.
|
|
final
void
|
wait()
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.
|
|
final
void
|
wait(long millis, int nanos)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
final
void
|
wait(long millis)
Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the
specified timeout expires.
|
|
From interface
java.lang.Appendable
|
From interface
java.io.Closeable
|
abstract
void
|
close()
Closes the object and release any system resources it holds.
|
|
From interface
java.io.Flushable
|
abstract
void
|
flush()
Flushes the object by writing out any buffered data to the underlying
output.
|
|
From interface
java.lang.AutoCloseable
|
abstract
void
|
close()
Closes the object and release any system resources it holds.
|
|
Fields
protected
Object
lock
The object used to synchronize access to the writer.
Protected Constructors
protected
Writer
()
Constructs a new Writer with this as the object used to
synchronize critical sections.
protected
Writer
(Object lock)
Constructs a new Writer with lock used to synchronize
critical sections.
| Parameters |
lock |
Object:
the Object used to synchronize critical sections. |
Public Methods
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.
| Parameters |
csq |
CharSequence:
the character sequence appended to the target. |
| Throws |
IOException |
if this writer is closed or another I/O error occurs.
|
public
Writer
append
(CharSequence csq, int start, int end)
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.
| Parameters |
csq |
CharSequence:
the character sequence appended to the target. |
start |
int:
the index of the first char in the character sequence appended
to the target. |
end |
int:
the index of the character following the last character of the
subsequence appended to the target. |
| Throws |
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.
|
public
Writer
append
(char c)
Appends the character c to the target. This method works the same
way as write(int).
| Parameters |
c |
char:
the character to append to the target stream. |
| Throws |
IOException |
if this writer is closed or another I/O error occurs.
|
public
abstract
void
close
()
Closes this writer. Implementations of this method should free any
resources associated with the writer.
| Throws |
IOException |
if an error occurs while closing this writer.
|
public
abstract
void
flush
()
Flushes this writer. Implementations of this method should ensure that
all buffered characters are written to the target.
| Throws |
IOException |
if an error occurs while flushing this writer.
|
public
void
write
(char[] buf)
Writes the entire character buffer buf to the target.
| Parameters |
buf |
char:
the non-null array containing characters to write. |
| Throws |
IOException |
if this writer is closed or another I/O error occurs.
|
public
void
write
(String str)
Writes the characters from the specified string to the target.
| Parameters |
str |
String:
the non-null string containing the characters to write. |
| Throws |
IOException |
if this writer is closed or another I/O error occurs.
|
public
abstract
void
write
(char[] buf, int offset, int count)
Writes count characters starting at offset in buf
to the target.
| Parameters |
buf |
char:
the non-null character array to write. |
offset |
int:
the index of the first character in buf to write. |
count |
int:
the maximum number of characters to write. |
| Throws |
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.
|
public
void
write
(String str, int offset, int count)
Writes count characters from str starting at offset to the target.
| Parameters |
str |
String:
the non-null string containing the characters to write. |
offset |
int:
the index of the first character in str to write. |
count |
int:
the number of characters from str to write. |
| Throws |
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.
|
public
void
write
(int oneChar)
Writes one character to the target. Only the two least significant bytes
of the integer oneChar are written.
| Parameters |
oneChar |
int:
the character to write to the target. |
| Throws |
IOException |
if this writer is closed or another I/O error occurs.
|