Class PipedInputStream
java.lang.Object
java.io.InputStream
ecmwf.common.technical.PipedInputStream
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]
The circular buffer into which incoming data is placed.protected int
The index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream. in<0 implies the buffer is empty, in==out implies the buffer is fullprotected int
The index of the position in the circular buffer at which the next byte of data will be read by this piped input stream.protected static final int
The default size of the pipe's circular input buffer. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a PipedInputStream so that it is not yetinvalid reference
connected
PipedInputStream
(int pipeSize) Creates a PipedInputStream so that it is not yetinvalid reference
connected
Creates a PipedInputStream so that it is connected to the piped output stream src.PipedInputStream
(PipedOutputStream src, int pipeSize) 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. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of bytes that can be read from this input stream without blocking.void
close()
Closes this piped input stream and releases any system resources associated with the stream.void
connect
(PipedOutputStream src) Causes this piped input stream to be connected to the piped output stream src.int
read()
Reads the next byte of data from this piped input stream.int
read
(byte[] b, int off, int len) Reads up to len bytes of data from this piped input stream into an array of bytes.protected void
receive
(int b) Receives a byte of data.Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Field Details
-
PIPE_SIZE
protected static final int PIPE_SIZEThe default size of the pipe's circular input buffer. This used to be a constant before the pipe size was allowed to change. This field will continue to be maintained for backward compatibility.- Since:
- JDK1.1
- See Also:
-
buffer
protected byte[] bufferThe circular buffer into which incoming data is placed.- Since:
- JDK1.1
-
in
protected int inThe index of the position in the circular buffer at which the next byte of data will be stored when received from the connected piped output stream. in<0 implies the buffer is empty, in==out implies the buffer is full- Since:
- JDK1.1
-
out
protected int outThe index of the position in the circular buffer at which the next byte of data will be read by this piped input stream.- Since:
- JDK1.1
-
-
Constructor Details
-
PipedInputStream
Creates a PipedInputStream so that it is connected to the piped output stream src. Data bytes written to src will then be available as input from this stream.- Parameters:
src
- the stream to connect to.- Throws:
IOException
- if an I/O error occurs.IOException
- if any.
-
PipedInputStream
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. Data bytes written to src will then be available as input from this stream.- Parameters:
src
- the stream to connect to.pipeSize
- the size of the pipe's buffer.- Throws:
IOException
- if an I/O error occurs.IllegalArgumentException
- if pipeSize invalid input: '<'= 0.IOException
- if any.- Since:
- 1.6
-
PipedInputStream
public PipedInputStream()Creates a PipedInputStream so that it is not yetinvalid reference
connected
-
PipedInputStream
public PipedInputStream(int pipeSize) Creates a PipedInputStream so that it is not yetinvalid reference
connected
- Parameters:
pipeSize
- the size of the pipe's buffer.- Throws:
IllegalArgumentException
- if pipeSize invalid input: '<'= 0.- Since:
- 1.6
-
-
Method Details
-
connect
Causes this piped input stream to be connected to the piped output stream src. If this object is already connected to some other piped output stream, an IOException is thrown.If src is an unconnected piped output stream and snk is an unconnected piped input stream, they may be connected by either the call:
snk.connect(src)
or the call:
src.connect(snk)
The two calls have the same effect.
- Parameters:
src
- The piped output stream to connect to.- Throws:
IOException
- if an I/O error occurs.IOException
- if any.
-
receive
Receives a byte of data. This method will block if no input is available.- Parameters:
b
- the byte being received- Throws:
IOException
- If the pipe is broken,invalid reference
unconnected
IOException
- if any.- Since:
- JDK1.1
-
read
Reads the next byte of data from this piped input stream. The value byte is returned as an int in the range 0 to 255. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.- Specified by:
read
in classInputStream
- Throws:
IOException
- if the pipe isinvalid reference
unconnected
-
read
Reads up to len bytes of data from this piped input stream into an array of bytes. Less than len bytes will be read if the end of the data stream is reached or if len exceeds the pipe's buffer size. If len is zero, then no bytes are read and 0 is returned; otherwise, the method blocks until at least 1 byte of input is available, end of the stream has been detected, or an exception is thrown.- Overrides:
read
in classInputStream
- Throws:
IOException
- if the pipe is broken,invalid reference
unconnected
NullPointerException
- If b is null.IndexOutOfBoundsException
- If off is negative, len is negative, or len is greater than b.length - off
-
available
Returns the number of bytes that can be read from this input stream without blocking.- Overrides:
available
in classInputStream
- Throws:
IOException
- if an I/O error occurs.- Since:
- JDK1.0.2
-
close
Closes this piped input stream and releases any system resources associated with the stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- if an I/O error occurs.
-