|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.ByteArrayInputStream
public class ByteArrayInputStream
ByteArrayInputStream 套件含一個內部緩衝區,該緩衝區包含從串流中讀取的位元組。內部計數器追蹤 read 方法要提供的下一個位元組。
關閉 ByteArrayInputStream 無效。此類別中的方法在關閉此串流後仍可被調用,而不會產生任何 IOException。
StringBufferInputStream| 欄位摘要 | |
|---|---|
protected byte[] |
buf
由該串流的創建者提供的 byte 陣列。 |
protected int |
count
比輸入串流緩衝區中最後一個有效字元的索引大一的索引。 |
protected int |
mark
串流中當前的標記位置。 |
protected int |
pos
要從輸入串流緩衝區中讀取的下一個字元的索引。 |
| 建構子摘要 | |
|---|---|
ByteArrayInputStream(byte[] buf)
創建一個 ByteArrayInputStream,使用 buf 作為其緩衝區陣列。 |
|
ByteArrayInputStream(byte[] buf,
int offset,
int length)
創建 ByteArrayInputStream,使用 buf 作為其緩衝區陣列。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可從此輸入串流讀取(或跳過)的剩餘位元組數。 |
void |
close()
關閉 ByteArrayInputStream 無效。 |
void |
mark(int readAheadLimit)
設置串流中的當前標記位置。 |
boolean |
markSupported()
測試此 InputStream 是否支持 mark/reset。 |
int |
read()
從此輸入串流中讀取下一個資料位元組。 |
int |
read(byte[] b,
int off,
int len)
將最多 len 個資料位元組從此輸入串流讀入 byte 陣列。 |
void |
reset()
將緩衝區的位置重置為標記位置。 |
long |
skip(long n)
從此輸入串流中跳過 n 個輸入位元組。 |
| 從類別 java.io.InputStream 繼承的方法 |
|---|
read |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 欄位詳細資訊 |
|---|
protected byte[] buf
buf[0] 到 buf[count-1] 是只能從串流中讀取的位元組;元素 buf[pos] 是要讀取的下一個位元組。
protected int pos
count 值。從輸入串流緩衝區中讀取的下一個位元組是 buf[pos]。
protected int mark
mark() 方法可將其標記在緩衝區內的另一個位置處。通過 reset() 方法將當前緩衝區位置設置為此點。
如果尚未設置標記,則標記值是傳遞給建構子的偏移量(如果未提供偏移量,則標記值為 0)。
protected int count
buf 的長度。它比 buf 中最後一個可從輸入串流緩衝區中讀取的位元組位置大一。
| 建構子詳細資訊 |
|---|
public ByteArrayInputStream(byte[] buf)
ByteArrayInputStream,使用 buf 作為其緩衝區陣列。該緩衝區陣列不是複製得到的。pos 的初始值是 0,count 的初始值是 buf 的長度。
buf - 輸入緩衝區。
public ByteArrayInputStream(byte[] buf,
int offset,
int length)
ByteArrayInputStream,使用 buf 作為其緩衝區陣列。pos 的初始值是 offset,count 的初始值是 offset+length 和 buf.length 中的最小值。該緩衝區陣列不是複製得到的。將該緩衝區的標記設置為指定的偏移量。
buf - 輸入緩衝區。offset - 緩衝區中要讀取的第一個位元組的偏移量。length - 從緩衝區中讀取的最大位元組數。| 方法詳細資訊 |
|---|
public int read()
0 到 255 範圍內的 int 位元組值。如果因為到達串流末尾而沒有可用的位元組,則返回值 -1。
此 read 方法不會阻塞。
InputStream 中的 read-1。
public int read(byte[] b,
int off,
int len)
len 個資料位元組從此輸入串流讀入 byte 陣列。如果 pos 等於 count,則返回 -1 指示檔案結束。否則,讀取的位元組數 k 等於 len 和 count-pos 中的較小者。如果 k 是正數,則以 System.arraycopy 執行的方式將 buf[pos] 到 buf[pos+k-1] 的位元組複製到 b[off] 到 b[off+k-1] 中。將值 k 與 pos 相加並返回 k。
此 read 方法不會阻塞。
InputStream 中的 readb - 存儲讀入資料的緩衝區。off - 目標陣列 b 的起始偏移量。len - 讀取的最大位元組數。
-1。
NullPointerException - 如果 b 為 null。
IndexOutOfBoundsException - 如果 off 為負,len 為負,或者 len 大於 b.length - offInputStream.read()public long skip(long n)
n 個輸入位元組。如果已到達輸入串流末尾,則可能會跳過較少的位元組。實際跳過的位元組數 k 等於 n 和 count-pos 中的較小者。將值 k 與 pos 相加並返回 k。
InputStream 中的 skipn - 要跳過的位元組數。
public int available()
返回值是 count - pos,它是要從輸入緩衝區中讀取的剩餘位元組數。
InputStream 中的 availablepublic boolean markSupported()
InputStream 是否支持 mark/reset。ByteArrayInputStream 的 markSupported 方法始終返回 true。
InputStream 中的 markSupportedtrue;否則返回 false。InputStream.mark(int),
InputStream.reset()public void mark(int readAheadLimit)
如果尚未設置標記,則標記值是傳遞給建構子的偏移量(如果未提供偏移量,則標記值為 0)。
註:readAheadLimit 對於此類別沒有意義。
InputStream 中的 markreadAheadLimit - 在標記位置失效前可以讀取位元組的最大限制。InputStream.reset()public void reset()
InputStream 中的 resetInputStream.mark(int),
IOException
public void close()
throws IOException
Closeable 中的 closeInputStream 中的 closeIOException - 如果發生 I/O 錯誤。
|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
版權所有 2008 Sun Microsystems, Inc. 保留所有權利。請遵守GNU General Public License, version 2 only。