? NullInputStream
java.lang.Object
java.io.InputStream
org.apache.commons.io.input.NullInputStream
- ????????:
Closeable
,AutoCloseable
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 } } }
- ???????:
- 1.3
-
?????
????????Create anInputStream
that emulates a size 0 stream which supports marking and does not throw EOFException.NullInputStream
(long size) Create anInputStream
that emulates a specified size which supports marking and does not throw EOFException.NullInputStream
(long size, boolean markSupported, boolean throwEofException) Create anInputStream
that emulates a specified size with option settings. -
????
??????????int
Return the number of bytes that can be read.void
close()
Close this input stream - resets the internal state to the initial values.long
Return the current position.long
getSize()
Return the size thisInputStream
emulates.void
mark
(int readlimit) Mark the current position.boolean
Indicates whether mark is supported.protected int
Return a byte value for theread()
method.protected void
processBytes
(byte[] bytes, int offset, int length) Process the bytes for theread(byte[], offset, length)
method.int
read()
Read a byte.int
read
(byte[] bytes) Read some bytes into the specified array.int
read
(byte[] bytes, int offset, int length) Read the specified number bytes into an array.void
reset()
Reset the stream to the point when mark was last called.long
skip
(long numberOfBytes) Skip a specified number of bytes.??????? java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
???????
-
NullInputStream
public NullInputStream()Create anInputStream
that emulates a size 0 stream which supports marking and does not throw EOFException.- ???????:
- 2.7
-
NullInputStream
Create anInputStream
that emulates a specified size which supports marking and does not throw EOFException.- ??:
size
- The size of the input stream to emulate.
-
NullInputStream
Create anInputStream
that emulates a specified size with option settings.- ??:
size
- The size of the input stream to emulate.markSupported
- Whether this instance will support themark()
functionality.throwEofException
- Whether this implementation will throw anEOFException
or return -1 when the end of file is reached.
-
-
??????
-
getPosition
Return the current position.- ??:
- the current position.
-
getSize
Return the size thisInputStream
emulates.- ??:
- The size of the input stream to emulate.
-
available
Return the number of bytes that can be read.- ??:
available
???InputStream
- ??:
- The number of bytes that can be read.
-
close
Close this input stream - resets the internal state to the initial values.- ???:
close
????AutoCloseable
- ???:
close
????Closeable
- ??:
close
???InputStream
- ??:
IOException
- If an error occurs.
-
mark
Mark the current position.- ??:
mark
???InputStream
- ??:
readlimit
- The number of bytes before this marked position is invalid.- ??:
UnsupportedOperationException
- if mark is not supported.
-
markSupported
Indicates whether mark is supported.- ??:
markSupported
???InputStream
- ??:
- Whether mark is supported or not.
-
read
Read a byte.- ???:
read
???InputStream
- ??:
- Either The byte value returned by
processByte()
or-1
if the end of file has been reached andthrowEofException
is set tofalse
. - ??:
EOFException
- if the end of file is reached andthrowEofException
is set totrue
.IOException
- if trying to read past the end of file.
-
read
Read some bytes into the specified array.- ??:
read
???InputStream
- ??:
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 tofalse
. - ??:
EOFException
- if the end of file is reached andthrowEofException
is set totrue
.IOException
- if trying to read past the end of file.
-
read
Read the specified number bytes into an array.- ??:
read
???InputStream
- ??:
bytes
- The byte array to read into.offset
- The offset to start reading bytes into.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 tofalse
. - ??:
EOFException
- if the end of file is reached andthrowEofException
is set totrue
.IOException
- if trying to read past the end of file.
-
reset
Reset the stream to the point when mark was last called.- ??:
reset
???InputStream
- ??:
UnsupportedOperationException
- if mark is not supported.IOException
- If no position has been marked or the read limit has been exceed since the last position was marked.
-
skip
Skip a specified number of bytes.- ??:
skip
???InputStream
- ??:
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 tofalse
. - ??:
EOFException
- if the end of file is reached andthrowEofException
is set totrue
.IOException
- if trying to read past the end of file.
-
processByte
Return a byte value for theread()
method.This implementation returns zero.
- ??:
- This implementation always returns zero.
-
processBytes
Process the bytes for theread(byte[], offset, length)
method.This implementation leaves the byte array unchanged.
- ??:
bytes
- The byte arrayoffset
- The offset to start at.length
- The number of bytes.
-