public abstract class Reader implement Readable , closeable
IOException: read()、skip()、ready()、close()、
mark(If the stream does not support mark operation)
reset()If the stream has not been marked, or if the mark has been invalidated, or if the stream does not support reset(),
subclass must override : read(char[] , int ,int ) close() markSupport()
blocked while invoking : read (util some input is available , an I/O error occurs ,or the end of the stream is reached)
skip(util some characters ara available ,an I/O error occurs , or the end of the stream reached)
Abstract class for reading character streams. The only methods that a subclass must implement areread(char[] , int , int )and close()。Most subclasses ,however ,will overrite some of themethods defined here in order to provide higher efficiently , additional functionality ,or both
protected Object lock:
The object used to synchronized operations on the stream
protected Reader():
Create a new character-stream reader whose critical sections will sychronized on the reader itselt
protected Reader(Object lock)
Create a new character-stream reader whose critical section willsychronized on the given object
public int read(CharBuffer target) throws IOException
Attempts to read characters into the specified characterbuffer. Thebuffer used as a repository(储藏室)of the characters as-is:the onlychanges made are the results of a put operation
return : The number of the characters added to the buffer ,or -1 if the sourcs of characters is at its end
public int read() throws IOException
Read a single character The method will block util a character is avaiable ,an I/O error occurs , or the end of the stream is reached
public abstract int read(char[] cbuf , int off , int len) throws IOException
Reads charactrers into a portion of an array .This method will block util some input is available , an I/O error occurs ,or the end of the stream is reached
off:Offset at which to start storing characters
public abstract void close() throws IOException
CLoses the stream and releases any system resources associated with it.Once the stream has been closed , further read() , ready(),mark(),reset(),orskip() invocations wilthrow an IOException.Close a previously closed stream has no effect
Specifiedby: close in the interface Closeable and close in the AutoCLoseable
public long skip(int n) throws IOException
Skips(跳过,略过) character.This method will block util some characters ara available ,an I/O error occurs , or the end of the stream reached
n:The number of characters to skip
return:The number of characters actually skip
throws:IllegalArgumentException if n<0
public boolean ready() throws IOException
Tells(判断)wheather this stream is ready to read
reaturn:True:if the next read(0is guaranteed not to block for input
note that:reutrn false does not guarantee the next read will block
public void mark(int readAheadLimit) throws IOException
Marks the present position in the stream,Subsequence(接下来随后)calls toreset()will attemptto reposition the stream to this point,Not all character-input streams support the mark() operation
Parameters:Limit on the number of the characters that may be read while still preserving the mark.After reading this many characters , attempting to reset the stream may fail
Throws:If the stream does not support mark() or if some other I/O error occurs
public boolean markSupported()
Tells wheather this stream supports the mark() operation The default implementation always returns false .Subclasses should override this method
public void reset() throws IOException
Resets the stream, IF the stream has been marked , then attempt to repasition it to the mark .If the stream has not been marked , then attemot to reset it in some way approciation to the particular stream for example by repositioning it to its starting point Not alll charcter-input streams support the reset() operation , and some support reset() without supportng mark()
Throws:If the stream has not been marked , or if the maok has been invalidated , or if the stream doen not support reset() or some other I/O error occurs