| java.lang.Object java.io.InputStream org.apache.commons.io.input.NullInputStream
NullInputStream | public class NullInputStream extends InputStream (Code) | | A functional, light weight
InputStream that emulates
a stream of a specified size.
This implementation provides a light weight
object for testing with an
InputStream where the contents don't matter.
One use case would be for testing the handling of
large
InputStream as it can emulate that
scenario without the overhead of actually processing
large numbers of bytes - significantly speeding up
test execution times.
This implementation returns zero from the method that
reads a byte and leaves the array unchanged in the read
methods that are passed a byte array.
If alternative data is required the processByte() and
processBytes() methods can be implemented to generate
data, for example:
public class TestInputStream extends NullInputStream {
public TestInputStream(int size) {
super(size);
}
protected int processByte() {
return ... // return required value here
}
protected void processBytes(byte[] bytes, int offset, int length) {
for (int i = offset; i < length; i++) {
bytes[i] = ... // set array value here
}
}
}
since: Commons IO 1.3 version: $Revision: 463529 $ |
Constructor Summary | |
public | NullInputStream(long size) Create an
InputStream that emulates a specified size
which supports marking and does not throw EOFException. | public | NullInputStream(long size, boolean markSupported, boolean throwEofException) Create an
InputStream that emulates a specified
size with option settings. |
Method Summary | |
public int | available() Return the number of bytes that can be read. | public void | close() Close this input stream - resets the internal state to
the initial values. | public long | getPosition() Return the current position. | public long | getSize() Return the size this
InputStream emulates. | public synchronized void | mark(int readlimit) Mark the current position. | public boolean | markSupported() Indicates whether mark is supported. | protected int | processByte() Return a byte value for the read() method. | protected void | processBytes(byte[] bytes, int offset, int length) Process the bytes for the read(byte[], offset, length)
method. | public int | read() Read a byte. | public int | read(byte[] bytes) Read some bytes into the specified array. | public int | read(byte[] bytes, int offset, int length) Read the specified number bytes into an array.
Parameters: bytes - The byte array to read into. Parameters: offset - The offset to start reading bytes into. Parameters: length - The number of bytes to read. | public synchronized void | reset() Reset the stream to the point when mark was last called. | public long | skip(long numberOfBytes) Skip a specified number of bytes.
Parameters: numberOfBytes - The number of bytes to skip. |
NullInputStream | public NullInputStream(long size)(Code) | | Create an
InputStream that emulates a specified size
which supports marking and does not throw EOFException.
Parameters: size - The size of the input stream to emulate. |
NullInputStream | public NullInputStream(long size, boolean markSupported, boolean throwEofException)(Code) | | Create an
InputStream that emulates a specified
size with option settings.
Parameters: size - The size of the input stream to emulate. Parameters: markSupported - Whether this instance will supportthe mark() functionality. Parameters: throwEofException - Whether this implementationwill throw an EOFException or return -1 when theend of file is reached. |
available | public int available()(Code) | | Return the number of bytes that can be read.
The number of bytes that can be read. |
close | public void close() throws IOException(Code) | | Close this input stream - resets the internal state to
the initial values.
throws: IOException - If an error occurs. |
getPosition | public long getPosition()(Code) | | Return the current position.
the current position. |
getSize | public long getSize()(Code) | | Return the size this
InputStream emulates.
The size of the input stream to emulate. |
mark | public synchronized void mark(int readlimit)(Code) | | Mark the current position.
Parameters: readlimit - The number of bytes before this marked positionis invalid. throws: UnsupportedOperationException - if mark is not supported. |
markSupported | public boolean markSupported()(Code) | | Indicates whether mark is supported.
Whether mark is supported or not. |
processByte | protected int processByte()(Code) | | Return a byte value for the read() method.
This implementation returns zero.
This implementation always returns zero. |
processBytes | protected void processBytes(byte[] bytes, int offset, int length)(Code) | | Process the bytes for the read(byte[], offset, length)
method.
This implementation leaves the byte array unchanged.
Parameters: bytes - The byte array Parameters: offset - The offset to start at. Parameters: length - The number of bytes. |
read | public int read() throws IOException(Code) | | Read a byte.
Either The byte value returned by processByte() or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
read | public int read(byte[] bytes) throws IOException(Code) | | Read some bytes into the specified array.
Parameters: bytes - The byte array to read into The number of bytes read or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
read | public int read(byte[] bytes, int offset, int length) throws IOException(Code) | | Read the specified number bytes into an array.
Parameters: bytes - The byte array to read into. Parameters: offset - The offset to start reading bytes into. Parameters: length - The number of bytes to read. The number of bytes read or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
reset | public synchronized void reset() throws IOException(Code) | | Reset the stream to the point when mark was last called.
throws: UnsupportedOperationException - if mark is not supported. throws: IOException - If no position has been markedor the read limit has been exceed since the last position wasmarked. |
skip | public long skip(long numberOfBytes) throws IOException(Code) | | Skip a specified number of bytes.
Parameters: numberOfBytes - The number of bytes to skip. The number of bytes skipped or -1 if the end of file has been reached andthrowEofException is set to false . throws: EOFException - if the end of file is reached andthrowEofException is set to true . throws: IOException - if trying to read past the end of file. |
|
|