public class NullInputStream extends InputStream
Constructor and Description |
---|
NullInputStream(boolean returnError)
Create a NullInputStream that will either always throw an IOException
or will always return EOF.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes the stream.
|
int |
read()
This method reads an unsigned byte from the input stream and returns it
as an int in the range of 0-255.
|
int |
read(byte[] dest,
int offset,
int count)
This method read bytes from a stream and stores them into a
caller supplied buffer.
|
long |
skip(long toSkip)
This method skips the specified number of bytes in the stream.
|
available, finalize, hashCode, mark, markSupported, read, reset
public NullInputStream(boolean returnError)
returnError
- if this is true any attempted read will throw an IOException,
otherwise it will return EOF.public int read() throws IOException
InputStream
This method will block until the byte can be read.
read
in class InputStream
IOException
- If an error occurspublic int read(byte[] dest, int offset, int count) throws IOException
InputStream
off
into the buffer and attempts to read
len
bytes. This method can return before reading the
number of bytes requested. The actual number of bytes read is
returned as an int. A -1 is returned to indicate the end of the
stream.
This method will block until some data can be read.
This method operates by calling the single byte read()
method
in a loop until the desired number of bytes are read. The read loop
stops short if the end of the stream is encountered or if an IOException
is encountered on any read operation except the first. If the first
attempt to read a bytes fails, the IOException is allowed to propagate
upward. And subsequent IOException is caught and treated identically
to an end of stream condition. Subclasses can (and should if possible)
override this method to provide a more efficient implementation.
read
in class InputStream
dest
- The array into which the bytes read should be storedoffset
- The offset into the array to start storing bytescount
- The requested number of bytes to readIOException
- If an error occurs.public long skip(long toSkip) throws IOException
InputStream
This method reads and discards bytes into a byte array until the specified number of bytes were skipped or until either the end of stream is reached or a read attempt returns a short count. Subclasses can override this metho to provide a more efficient implementation where one exists.
skip
in class InputStream
toSkip
- The requested number of bytes to skipIOException
- If an error occurspublic void close() throws IOException
InputStream
IOException
This method does nothing in this class, but subclasses may override this method in order to provide additional functionality.
close
in class InputStream
IOException
- If an error occurs, which can only happen
in a subclass