📜  Java.io.PipedInputStream类

📅  最后修改于: 2020-11-15 02:48:31             🧑  作者: Mango


介绍

Java.io.PipedInputStream类是可以连接到管道输出流的管道输入流,然后管道输入流提供将任何数据字节写入管道输出流。以下是关于PipedInputStream的要点-

  • 管道输入流包含一个缓冲区,在限制范围内将读取操作与写入操作分离。

  • 不建议尝试从单个线程使用两个对象,因为这可能使线程死锁。

  • 如果向连接的管道输出流提供数据字节的线程不再活动,则认为管道已损坏。

类声明

以下是Java.io.PipedInputStream类的声明-

public class PipedInputStream
   extends InputStream

领域

以下是Java.io.PipedInputStream类的字段-

  • protected byte [] buffer-这是将传入数据放入其中的循环缓冲区。

  • protected int in-这是循环缓冲区中从连接的管道输出流接收到的下一个数据字节将存储的位置的索引。

  • protected int out-这是循环缓冲区中该管道输入流将在其下一个数据字节读取的位置的索引。

  • protected static int PIPE_SIZE-这是管道的循环输入缓冲区的默认大小。

类的构造函数

Sr.No. Constructor & Description
1

PipedInputStream()

This creates a PipedInputStream so that it is not yet connected.

2

PipedInputStream(int pipeSize)

This creates a PipedInputStream so that it is not yet connected and uses the specified pipe size for the pipe’s buffer.

3

PipedInputStream(PipedOutputStream src)

This creates a PipedInputStream so that it is connected to the piped output stream src.

4

PipedInputStream(PipedOutputStream src, int pipeSize)

This creates a PipedInputStream so that it is connected to the piped output stream src and uses the specified pipe size for the pipe’s buffer.

类方法

Sr.No. Method & Description
1 int available()

This method returns the number of bytes that can be read from this input stream without blocking.

2 void close()

This method closes this piped input stream and releases any system resources associated with the stream.

3 void connect(PipedOutputStream src)

This method causes this piped input stream to be connected to the piped output stream src.

4 int read()

This method reads the next byte of data from this piped input stream.

5 int read(byte[] b, int off, int len)

This method reads up to len bytes of data from this piped input stream into an array of bytes.

6 protected void receive(int b)

This method receives a byte of data.

方法继承

此类从以下类继承方法-

  • Java.io.InputStream
  • Java对象