Writer

public  abstract class Writer extends Object implements Appendable ,Closeable , Flushable

 

Abstarct class for writing to character streams, The only methods that a subclass must implement are write(char[] , int ,int),flush() , close() .Most subclasses , howerver ,will override some of the methods defined here inorder to provide higher efficency ,additional functionality , or both

 

protected Object luck

                         The object used to sychronized  operations on the stream, For efficiency , a character-stream object may use an object other than itself to protect critical-section A subclass should there use the object in the field rather than this or syvhronized method

 

public void write(int c) throws IOException

                      writes a single character.The character to be written is contained in the 16 loworder bits of the given integer value ; the 16-high-order bits are ignored

                    subclasses that intened to support efficient single-character output shoule override this method

 

public Writer append(CharSuquence csq) throws IOException

                   Appends the specified character suquence to the writer

                  An invocation of this method of the form out.append(csq) behaves in exactly ths same way as out.write(csq.toString())

                   Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking the toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

 

 

 

public abstract void flush() throws IOException

             FLushes the stream If the stream has saved any characters from the various write()methods in a buffer ,write them immediately to their intend destination.THen if that destination is anther character or byte stream ,flush it.Thus one flush() invocation will flush at the buffers in a chain of Writers and OutputStreram()

 

If the intended destination of this stream is an abstraction provided by the underlying operating system, for example a file, then flushing the stream guarantees only that bytes previously written to the stream are passed to the operating system for writing; it does not guarantee that they are actually written to a physical device such as a disk drive.

 

 

public abstract void close()
    
Closes the stream, flushing it first. Once the stream has been closed, further write() or flush() invocations will cause an IOException to be thrown. Closing a previously closed stream has no effect.

 

發佈了44 篇原創文章 · 獲贊 15 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章