|
JavaTM 2 Platform Standard Ed. 6 |
|||||||||
| 上一個類別 下一個類別 | 框架 無框架 | |||||||||
| 摘要: 巢狀 | 欄位 | 建構子 | 方法 | 詳細資訊: 欄位 | 建構子 | 方法 | |||||||||
java.lang.Objectjava.io.InputStream
java.io.PipedInputStream
public class PipedInputStream
管道輸入串流應該連接到管道輸出串流;管道輸入串流提供要寫入管道輸出串流的所有資料位元組。通常,資料由某個執行緒從
PipedInputStream 物件讀取,並由其他執行緒將其寫入到相應的 PipedOutputStream。不建議對這兩個物件嘗試使用單個執行緒,因為這樣可能死鎖執行緒。管道輸入串流包含一個緩衝區,可在緩衝區限定的範圍內將讀操作和寫操作分離開。
如果向連接管道輸出串流提供資料位元組的執行緒不再存在,則認為該管道已損壞。
PipedOutputStream
| 欄位摘要 | |
|---|---|
protected byte[] |
buffer
放置傳入資料的循環緩衝區。 |
protected int |
in
循環緩衝區中位置的索引,當從連接的管道輸出串流中接收到下一個資料位元組時,會將其存儲到該位置。 |
protected int |
out
循環緩衝區中位置的索引,此管道輸入串流將從該位置讀取下一個資料位元組。 |
protected static int |
PIPE_SIZE
管道循環輸入緩衝區的預設大小。 |
| 建構子摘要 | |
|---|---|
PipedInputStream()
創建尚未連接的 PipedInputStream。 |
|
PipedInputStream(int pipeSize)
創建一個尚未連接的 PipedInputStream,並對管道緩衝區使用指定的管道大小。 |
|
PipedInputStream(PipedOutputStream src)
創建 PipedInputStream,使其連接到管道輸出串流 src。 |
|
PipedInputStream(PipedOutputStream src,
int pipeSize)
創建一個 PipedInputStream,使其連接到管道輸出串流 src,並對管道緩衝區使用指定的管道大小。 |
|
| 方法摘要 | |
|---|---|
int |
available()
返回可以不受阻塞地從此輸入串流中讀取的位元組數。 |
void |
close()
關閉此管道輸入串流並釋放與該串流相關的所有系統資源。 |
void |
connect(PipedOutputStream src)
使此管道輸入串流連接到管道輸出串流 src。 |
int |
read()
讀取此管道輸入串流中的下一個資料位元組。 |
int |
read(byte[] b,
int off,
int len)
將最多 len 個資料位元組從此管道輸入串流讀入 byte 陣列。 |
protected void |
receive(int b)
接收資料位元組。 |
| 從類別 java.io.InputStream 繼承的方法 |
|---|
mark, markSupported, read, reset, skip |
| 從類別 java.lang.Object 繼承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| 欄位詳細資訊 |
|---|
protected static final int PIPE_SIZE
protected byte[] buffer
protected int in
in<0 意味著緩衝區為空,in==out 意味著緩衝區已滿。
protected int out
| 建構子詳細資訊 |
|---|
public PipedInputStream(PipedOutputStream src)
throws IOException
PipedInputStream,使其連接到管道輸出串流 src。寫入 src 的資料位元組可用作此串流的輸入。
src - 要連接的串流。
IOException - 如果發生 I/O 錯誤。
public PipedInputStream(PipedOutputStream src,
int pipeSize)
throws IOException
PipedInputStream,使其連接到管道輸出串流 src,並對管道緩衝區使用指定的管道大小。
寫入 src 的資料位元組可用作此串流的輸入。
src - 要連接的串流。pipeSize - 管道緩衝區的大小。
IOException - 如果發生 I/O 錯誤。
IllegalArgumentException - 如果 pipeSize <= 0。public PipedInputStream()
PipedInputStream。在使用前必須將其連接到 PipedOutputStream。
public PipedInputStream(int pipeSize)
PipedInputStream,並對管道緩衝區使用指定的管道大小。在使用前必須將其連接到 PipedOutputStream。
pipeSize - 管道緩衝區的大小。
IllegalArgumentException - 如果 pipeSize <= 0。| 方法詳細資訊 |
|---|
public void connect(PipedOutputStream src)
throws IOException
src。如果此物件已經連接到其他某個管道輸出串流,則拋出 IOException。
如果 src 為未連接的管道輸出串流,snk 為未連接的管道輸入串流,則可以通過以下任一調用使其連接:
snk.connect(src)
或:
src.connect(snk)
這兩個調用的效果相同。
src - 要連接的管道輸出串流。
IOException - 如果發生 I/O 錯誤。
protected void receive(int b)
throws IOException
b - 將接收的位元組
IOException - 如果管道損壞、未連接、關閉,或者發生 I/O 錯誤。
public int read()
throws IOException
0 到 255 範圍內的 int 位元組值。在輸入資料可用、檢測到串流的末尾或者拋出異常前,此方法一直阻塞。
InputStream 中的 read-1。
IOException - 如果管道未連接、損壞、關閉,或者發生 I/O 錯誤。
public int read(byte[] b,
int off,
int len)
throws IOException
len 個資料位元組從此管道輸入串流讀入 byte 陣列。如果已到達資料串流的末尾,或者 len 超出管道緩衝區大小,則讀取的位元組數將少於 len。如果 len 為 0,則不讀取任何位元組並返回 0;否則,在至少 1 個輸入位元組可用、檢測到串流末尾、拋出異常前,該方法將一直阻塞。
InputStream 中的 readb - 讀入資料的緩衝區。off - 目標陣列 b 中的初始偏移量。len - 讀取的最多位元組數。
-1。
NullPointerException - 如果 b 為 null。
IndexOutOfBoundsException - 如果 off 為負,len 為負,或者 len 大於 b.length - off
IOException - 如果管道損壞、未連接、關閉,或者發生 I/O 錯誤。InputStream.read()
public int available()
throws IOException
InputStream 中的 availableclose() 方法關閉此輸入串流、管道未連接或已損壞,則返回 0。
IOException - 如果發生 I/O 錯誤。
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。