Reader

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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值