java.io.Writer
java.lang.Object
java.io.BufferedWriter, java.io.CharArrayWriter,
java.io.FilterWriter, java.io.OutputStreamWriter,
java.io.PipedWriter, java.io.PrintWriter,
java.io.StringWriter
None
New as of JDK 1.1
The Writer class is an abstract class that is the superclass of all classes that represent output character streams. Writer defines the basic output methods that all character streams provide. A similar hierarchy of classes, based around OutputStream, deals with byte streams instead of character streams.
Writer is designed so that write(int b) and write(char[]) both call write(char[], int, int). Thus, a subclass can simply override write(char[], int, int) and all of the write methods will work. Note that this is different from the design of OutputStream, where the write(int b) method is the catch-all method. The design of Writer is cleaner and more efficient.
Some Writer subclasses may implement buffering to increase efficiency. Writer provides a method--flush()--that tells the Writer to write any buffered output to the underlying device, which may be a disk drive or a network.
public abstract class java.io.Writer extends java.lang.Object { // Variables protected Object lock; // Constructors protected Writer(); protected Writer(Object lock); // Instance Methods public abstract void close(); public abstract void flush(); public void write(int c); public void write(char[] cbuf); public abstract void write(char[] cbuf, int off, int len); public void write(String str); public void write(String str, int off, int len); }
The object used to synchronize operations on this Writer object. For efficiency's sake, a particular implementation of a character stream can choose to synchronize its operations on something other than instances of itself. Thus, any subclass should synchronize on the lock object, instead of using a synchronized method or the this object.
This constructor creates a Writer that synchronizes on the Writer itself, or in other words, on the this object.
The object to use for synchronization.
This constructor creates a Writer that synchronizes on the given object.
If any kind of I/O error occurs.
This method flushes the writer and then closes it, releasing any system resources associated with it.
A subclass of Writer must implement this method.
If any kind of I/O error occurs.
This method forces any characters that may be buffered by this Writer to be written to the underlying device.
A subclass of Writer must implement this method.
The value to write.
If any kind of I/O error occurs.
This method writes a character containing the lowest sixteen bits of the given integer value.
The implementation of this method in Writer writes the character by calling write(cb, 1) where cb is a character array that contains the given value in cb[0]. Although it is not strictly necessary, a subclass that wants to provide efficient single-character writes should override this method.
An array of characters to write to the stream.
If any kind of I/O error occurs.
This method writes the given array of characters to the stream by calling write(cbuf, 0, cbuf.length).
A subclass does not usually need to override this method, as it can override write(char[], int, int) and have write(char[]) work automatically.
public abstract void write(char[] cbuf, int off, int len) throws IOException
An array of characters to write to the stream.
An offset into the array.
The number of characters to write.
If any kind of I/O error occurs.
This method writes len characters contained in the given array starting at index off.
A subclass of Writer must implement this method.
A string to write to the stream.
If any kind of I/O error occurs.
This method writes the given string to the stream by calling write(str,str.length).
A subclass does not usually need to override this method, as it can override write(char[], int, int) and have it work automatically.
A string to write to the stream.
An offset into the string.
The number of characters to write.
If any kind of I/O error occurs.
This method writes len characters contained in the given string starting at index off. The method does this by creating an array of characters for the specified portion of the string and then calling write(cb, 0, cb.length) on the character array cb.
A subclass does not usually need to override this method, as it can override write(char[], int, int) and have it work automatically.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
BufferedWriter, CharArrayWriter, FilterWriter, IOException, OutputStreamWriter, PipedWriter, PrintWriter, StringWriter