public class InputStreamWrapper
extends java.io.InputStream
InputStream
which accesses a contained
Stream
instance. This allows classes that use the standard Java
I/O features (in package java.io.*
) to transparently use
a P2J stream instead. That stream may be on a remote node.Modifier and Type | Field and Description |
---|---|
private Stream |
stream
The contained stream that does our real work.
|
Constructor and Description |
---|
InputStreamWrapper(Stream stream)
Construct an instance which wrappers the given stream.
|
Modifier and Type | Method and Description |
---|---|
int |
available()
Obtains an estimate of the number of bytes that can be read from this
stream without blocking.
|
void |
close()
Closes the input stream and releases OS resources associated with it.
|
int |
read()
Reads the next byte of data from the input stream.
|
int |
read(byte[] array,
int off,
int len)
Read a chunk of bytes from the current read position in the stream to the
offset calculated by given length or to the
EOF , whichever
comes first. |
private Stream stream
public InputStreamWrapper(Stream stream)
stream
- The P2J stream to wrap.public int read() throws java.io.IOException
int
, the actual value will always be
between 0 and 255 inclusive. When the end of the stream has been reached,
-1 is returned.
The underlying stream subclass determines the content of the result. Byte oriented streams such as pipes or files will return a byte while streams that generate keystrokes or characters may return a DBCS or Unicode character. Any data that is greater in size than a byte will be truncated!
This method blocks waiting for the data, the end of the stream or some exceptional condition.
read
in class java.io.InputStream
java.io.IOException
public int read(byte[] array, int off, int len) throws java.io.IOException
EOF
, whichever
comes first. The EOF
character is not returned.read
in class java.io.InputStream
array
- The array in which to save bytes.off
- The offset into the array at which to start saving bytes.len
- The maximum number of bytes to read.EOF
has been
reached). The number of bytes read will be the smaller
of the len
parameter or the actual bytes left
before the EOF
.java.io.IOException
- If an I/O error occurs.public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream