Abstract class for writing to character streams. The only methods that a subclass must implement are write(char[], int, int), flush(), and close(). Most subclasses, however, will override some of the methods defined here in order to provide higher efficiency, additional functionality, or both. Since
| 27 | * Since: JDK1.1, CLDC 1.0 See Also:OutputStreamWriter, Reader |
| 28 | */ |
| 29 | public abstract class Writer implements Appendable, AutoCloseable { |
| 30 | /** |
| 31 | * The object used to synchronize operations on this stream. For efficiency, a character-stream object may use an object other than itself to protect critical sections. A subclass should therefore use the object in this field rather than this or a synchronized method. |
| 32 | */ |
| 33 | protected java.lang.Object lock; |
| 34 | |
| 35 | /** |
| 36 | * Create a new character-stream writer whose critical sections will synchronize on the writer itself. |
| 37 | */ |
| 38 | protected Writer(){ |
| 39 | lock = this; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Create a new character-stream writer whose critical sections will synchronize on the given object. |
| 44 | * lock - Object to synchronize on. |
| 45 | */ |
| 46 | protected Writer(java.lang.Object lock){ |
| 47 | this.lock = lock; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Close the stream, flushing it first. Once a stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously-closed stream, however, has no effect. |
| 52 | */ |
| 53 | public abstract void close() throws java.io.IOException; |
| 54 | |
| 55 | /** |
| 56 | * Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams. |
| 57 | */ |
| 58 | public abstract void flush() throws java.io.IOException; |
| 59 | |
| 60 | /** |
| 61 | * Write an array of characters. |
| 62 | */ |
| 63 | public void write(char[] cbuf) throws java.io.IOException{ |
| 64 | write(cbuf, 0, cbuf.length); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Write a portion of an array of characters. |
| 69 | */ |
| 70 | public abstract void write(char[] cbuf, int off, int len) throws java.io.IOException; |
| 71 | |
| 72 | /** |
| 73 | * Write a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. |
| 74 | * Subclasses that intend to support efficient single-character output should override this method. |
| 75 | */ |
| 76 | public void write(int c) throws java.io.IOException{ |
| 77 | synchronized (lock) { |
| 78 | char oneCharArray[] = new char[1]; |
| 79 | oneCharArray[0] = (char) c; |
| 80 | write(oneCharArray); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Write a string. |
| 86 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected