Original link Author: Jakob Jenkov Translator: Li Jing ([email protected])
PipedInputStream can read the byte stream data from the pipeline, the code is as follows:
01 |
InputStream input = new PipedInputStream(pipedOutputStream); |
03 |
int data = input.read(); |
07 |
//do something with data... |
09 |
doSomethingWithData(data); |
Note that in order to be clear, the necessary exception handling is ignored. For more information about exception handling, refer to Java IO exception handling.
The read () method of PipedInputStream returns an int variable (translator Note: 0~255) that contains a byte content. If the Read () method returns 1, meaning that the program has read to the end of the stream, there is no more data in the stream to read, and you can close the stream. 1 is an int type, not a byte type, which is not the same.
Java IO Pipeline
As you can see, a pipedinputstream needs to be associated with a pipedoutputstream, and when the two flows are connected, a pipeline is formed. To learn more about pipelines in Java IO, refer to the Java IO pipeline.
original articles, reproduced please specify: reproduced from the Concurrent programming network –ifeve.com This article link address: Java io:pipedinputstream
Java Io:pipedinputstream