|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
public class BufferedInputStream
BufferedInputStream 為另一個輸入串流添加一些功能,即緩衝輸入以及支持 mark 和 reset 方法的能力。在創建 BufferedInputStream 時,會創建一個內部緩衝區陣列。在讀取或跳過串流中的位元組時,可根據需要從套件含的輸入串流再次填充該內部緩衝區,一次填充多個位元組。mark 操作記錄輸入串流中的某個點,reset 操作使得在從套件含的輸入串流中獲取新位元組之前,再次讀取自最後一次 mark 操作後讀取的所有位元組。
| 欄位摘要 | |
|---|---|
protected byte[] |
buf
存儲資料的內部緩衝區陣列。 |
protected int |
count
比緩衝區中最後一個有效位元組的索引大 1 的索引。 |
protected int |
marklimit
調用 mark 方法後,在後續調用 reset 方法失敗之前所允許的最大提前讀取量。 |
protected int |
markpos
最後一次調用 mark 方法時 pos 欄位的值。 |
protected int |
pos
緩衝區中的當前位置。 |
| 從類別 java.io.FilterInputStream 繼承的欄位 |
|---|
in |
| 建構子摘要 | |
|---|---|
BufferedInputStream(InputStream in)
創建一個 BufferedInputStream 並保存其參數,即輸入串流 in,以便將來使用。 |
|
BufferedInputStream(InputStream in,
int size)
創建具有指定緩衝區大小的 BufferedInputStream 並保存其參數,即輸入串流 in,以便將來使用。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可以從此輸入串流讀取(或跳過)、且不受此輸入串流接下來的方法調用阻塞的估計位元組數。 |
void |
close()
關閉此輸入串流並釋放與該串流關聯的所有系統資源。 |
void |
mark(int readlimit)
參見 InputStream 的 mark 方法的常規協定。 |
boolean |
markSupported()
測試此輸入串流是否支持 mark 和 reset 方法。 |
int |
read()
參見 InputStream 的 read 方法的常規協定。 |
int |
read(byte[] b,
int off,
int len)
從此位元組輸入串流中給定偏移量處開始將各位元組讀取到指定的 byte 陣列中。 |
void |
reset()
參見 InputStream 的 reset 方法的常規協定。 |
long |
skip(long n)
參見 InputStream 的 skip 方法的常規協定。 |
| 從類別 java.io.FilterInputStream 繼承的方法 |
|---|
read |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 欄位詳細資訊 |
|---|
protected volatile byte[] buf
protected int count
0 到 buf.length 的範圍內;從 buf[0] 到 buf[count-1] 的元素包含從底層輸入串流中獲取的緩衝輸入資料。
protected int pos
buf 陣列中讀取的下一個字元的索引。
此值始終處於 0 到 count 的範圍內。如果此值小於 count,則 buf[pos] 將作為下一個輸入位元組;如果此值等於 count,則下一次 read 或 skip 操作需要從套件含的輸入串流中讀取更多的位元組。
bufprotected int markpos
mark 方法時 pos 欄位的值。
此值始終處於 -1 到 pos 的範圍內。如果輸入串流中沒有被標記的位置,則此欄位為 -1。如果輸入串流中有被標記的位置,則 buf[markpos] 將用作 reset 操作後的第一個輸入位元組。如果 markpos 不是 -1,則從位置 buf[markpos] 到 buf[pos-1] 之間的所有位元組都必須保留在緩衝區陣列中(儘管對 count、pos 和 markpos 的值進行適當調整後,這些位元組可能移動到緩衝區陣列中的其他位置);除非 pos 與 markpos 的差超過 marklimit,否則不能將其丟棄。
mark(int),
posprotected int marklimit
mark 方法後,在後續調用 reset 方法失敗之前所允許的最大提前讀取量。只要 pos 與 markpos 之差超過 marklimit,就可以通過將 markpos 設置為 -1 來刪除該標記。
mark(int),
reset()| 建構子詳細資訊 |
|---|
public BufferedInputStream(InputStream in)
BufferedInputStream 並保存其參數,即輸入串流 in,以便將來使用。創建一個內部緩衝區陣列並將其存儲在 buf 中。
in - 底層輸入串流。
public BufferedInputStream(InputStream in,
int size)
BufferedInputStream 並保存其參數,即輸入串流 in,以便將來使用。創建一個長度為 size 的內部緩衝區陣列並將其存儲在 buf 中。
in - 底層輸入串流。size - 緩衝區大小。
IllegalArgumentException - 如果 size <= 0| 方法詳細資訊 |
|---|
public int read()
throws IOException
InputStream 的 read 方法的常規協定。
FilterInputStream 中的 read-1。
IOException - 如果已經調用其 close() 方法關閉了此輸入串流,或者發生 I/O 錯誤。FilterInputStream.in
public int read(byte[] b,
int off,
int len)
throws IOException
此方法實作了 類別相應 InputStream 方法的常規協定。另一個便捷之處在於,它將通過重複地調用底層串流的 readread 方法,嘗試讀取盡可能多的位元組。這種迭代的 read 會一直繼續下去,直到滿足以下條件之一:
read 方法返回 -1,指示檔案末尾(end-of-file),或者
available 方法返回 0,指示將阻塞後續的輸入請求。
read 返回 -1(指示檔案末尾),則此方法返回 -1。否則此方法返回實際讀取的位元組數。
鼓勵(但不是必須)此類別的各個子類別以相同的方式嘗試讀取盡可能多的位元組。
FilterInputStream 中的 readb - 目標緩衝區。off - 開始存儲位元組處的偏移量。len - 要讀取的最大位元組數。
-1。
IOException - 如果已經調用其 close() 方法關閉了此輸入串流,或者發生 I/O 錯誤。FilterInputStream.in
public long skip(long n)
throws IOException
InputStream 的 skip 方法的常規協定。
FilterInputStream 中的 skipn - 要跳過的位元組數。
IOException - 如果串流不支持尋找操作;或者已經調用其 close() 方法關閉了此輸入串流;或者發生 I/O 錯誤。
public int available()
throws IOException
此方法返回緩衝區中剩餘的待讀取位元組數 (count - pos) 與調用 in.available() 的結果之和。
FilterInputStream 中的 availableIOException - 如果已經調用其 close() 方法關閉了此輸入串流,或者發生 I/O 錯誤。public void mark(int readlimit)
InputStream 的 mark 方法的常規協定。
FilterInputStream 中的 markreadlimit - 在標記位置變為無效之前可以讀取位元組的最大限制。reset()
public void reset()
throws IOException
InputStream 的 reset 方法的常規協定。
如果 markpos 為 -1(尚未設置標記,或者標記已失效),則拋出 IOException。否則將 pos 設置為與 markpos 相等。
FilterInputStream 中的 resetIOException - 如果尚未標記此串流;或者標記已失效;或者已經調用其 close() 方法關閉了此輸入串流;或者發生 I/O 錯誤。mark(int)public boolean markSupported()
mark 和 reset 方法。BufferedInputStream 的 markSupported 方法返回 true。
FilterInputStream 中的 markSupportedboolean 值,指示此串流型別是否支持 mark 和 reset 方法。InputStream.mark(int),
InputStream.reset()
public void close()
throws IOException
Closeable 中的 closeFilterInputStream 中的 closeIOException - 如果發生 I/O 錯誤。FilterInputStream.in
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。