|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
org.wegra.io.RandomInputStream
InputStream which produces pseudorandom data. This class is not thread-safe.
Nested Class Summary | |
static class |
RandomInputStream.Test
Inner class for testing RandomInputStream |
Constructor Summary | |
RandomInputStream()
Creates a RandomInputStream as default setting. |
|
RandomInputStream(int size)
Creates a RandomInputStream has specific size. |
|
RandomInputStream(int size,
long seed)
Creates a RandomInputStream has specific seed and data size. |
|
RandomInputStream(long seed)
Creates a RandomInputStream has specific seed to generate pseudo-random data. |
Method Summary | |
int |
available()
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
void |
close()
Closes this input stream and releases any system resources associated with the stream. |
boolean |
markSupported()
Returns false , because this input stream doesn't support
mark operation. |
int |
read()
Reads the next byte of data from the input stream. |
int |
read(byte[] buffer)
Reads some number of bytes from the input stream and stores them into the buffer array buffer . |
int |
read(byte[] buffer,
int offset,
int length)
Reads up to length bytes of data from the input stream into
an array of bytes. |
void |
reset()
Throws IOException because this input stream does not support mark/reset operation. |
long |
skip(long number)
Skips over and discards number bytes of data from this input
stream. |
Methods inherited from class java.io.InputStream |
mark |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RandomInputStream()
public RandomInputStream(int size)
size
- size(length) of stream.public RandomInputStream(long seed)
seed
- seed to generate pseudo-random data.public RandomInputStream(int size, long seed)
size
- size of stream.seed
- seed to generate pseudo-random data.Method Detail |
public int available() throws java.io.IOException
java.io.IOException
- If this stream was closed already.public void close()
public boolean markSupported()
false
, because this input stream doesn't support
mark
operation.
InputStream.mark(int)
,
reset()
public int read() throws java.io.IOException
int
in the range 0
to
255
. If no byte is available because the end of the stream
has been reached, the value -1
is returned. This method
blocks until input data is available, the end of the stream is detected,
or an exception is thrown.
-1
if the end of the
stream is reached.
java.io.IOException
- If this stream was closed already.public int read(byte[] buffer) throws java.io.IOException
buffer
. The number of bytes actually read
is returned as an integer. This method blocks until input data is
available, end of file is detected, or an exception is thrown.
If buffer
is null
, a
NullPointerException
is thrown. If the length of
buffer
is zero, then no bytes are read and 0
is
returned; otherwise, there is an attempt to read at least one byte. If
no byte is available because the stream is at end of file, the value
-1
is returned; otherwise, at least one byte is read and
stored into buffer
.
The first byte read is stored into element buffer[0]
,
the next one into buffer[1]
, and so on. The number of bytes
read is, at most, equal to the length of b
. Let k be
the number of bytes actually read; these bytes will be stored in elements
buffer[0]
through buffer[
k - 1]
, leaving elements buffer[
k]
through buffer[buffer.length - 1]
unaffected.
If the first byte cannot be read for any reason other than end of
file, then an IOException
is thrown. In particular, an
IOException
is thrown if the input stream has been closed.
buffer
- the buffer into which the data is read.
-1
is there is no more data because the end of
the stream has been reached.
java.io.IOException
- Never throws.read(byte[], int, int)
public int read(byte[] buffer, int offset, int length) throws java.io.IOException
length
bytes of data from the input stream into
an array of bytes. An attempt is made to read as many as
length
bytes, but a smaller number may be read, possibly
zero. The number of bytes actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.
If buffer
is null
, a
NullPointerException
is thrown.
If offset
is negative, or length
is
negative, or offset + length
is greater than the length of
the array buffer
, then an IndexOutOfBoundsException
is thrown.
If length
is zero, then no bytes are read and
0
is returned; otherwise, there is an attempt to read at
least one byte. If no byte is available because the stream is at end of
file, the value -1
is returned; otherwise, at least one
byte is read and stored into buffer
.
The first byte read is stored into element buffer[offset]
, the next one into buffer[offset + 1]
, and so on.
The number of bytes read is, at most, equal to length
. Let
k be the number of bytes actually read; these bytes will be stored
in elements buffer[offset]
through buffer[offset +
k -1]
, leaving elements buffer[offset +
k]
through b[off + length - 1]
unaffected.
In every case, elements buffer[0]
through
buffer[offset]
and elements buffer[offset + length]
through buffer[buffer.length-1]
are unaffected.
If the first byte cannot be read for any reason other than end of
file, then an IOException
is thrown. In particular, an
IOException
is thrown if the input stream has been closed.
buffer
- the buffer into which the data is read.offset
- the start offset in array buffer
at which the data is written.length
- the maximum number of bytes to read.
-1
if there is no more data because the end of
the stream has been reached.
java.io.IOException
- If this stream was closed already.read()
public long skip(long number) throws java.io.IOException
number
bytes of data from this input
stream. The skip
method may, for a variety of reasons, end
up skipping over some smaller number of bytes, possibly 0
.
This may result from any of a number of conditions; reaching end of file
before number
bytes have been skipped is only one
possibility.
The actual number of bytes skipped is returned. If number
is negative, no bytes are skipped.
number
- the number of bytes to be skipped.
java.io.IOException
- If this stream was closed already.public void reset() throws java.io.IOException
java.io.IOException
- always if you call.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |