public class NativeRandomStream extends RandomStream
READ_ONLY, READ_WRITE
Modifier and Type | Method and Description |
---|---|
void |
close()
This method closes the stream.
|
protected void |
finalize()
This method (when overriden), will be called when the VM determines that the Object can be
garbage collected.
|
void |
flush()
This method forces any data that may have been buffered to be written
to the underlying output device.
|
long |
getLength()
Return the full length of the Stream.
|
long |
getPosition()
Return the current read/write stream pointer.
|
int |
hashCode()
Returns a hashCode for the object.
|
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[] data,
int offset,
int count)
This method read bytes from a stream and stores them into a
caller supplied buffer.
|
void |
setLength(long length)
Attempt to set the length of the stream if this is supported.
|
void |
setPosition(long newPosition)
Set the Stream position.
|
long |
skip(long n)
This method skips the specified number of bytes in the stream.
|
protected void |
throwCantWrite()
Throw an IOException indicating that you cannot write to this RandomStream.
|
static RandomStream |
toRandomStream(int nativeStream,
String mode) |
void |
write(byte[] data,
int offset,
int count)
This method writes
len bytes from the specified array
b starting at index off into the array. |
void |
write(int b)
This method writes a single byte to the output stream.
|
canSetLength, isOpenForWriting, isReadWrite, mark, markSupported, reset, setMode, toOutputStream, validateMode, write
available, read
public static RandomStream toRandomStream(int nativeStream, String mode)
public int hashCode()
Object
hashCode
in class InputStream
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[] data, 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
data
- 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 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 subclasspublic long skip(long n) 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 RandomStream
n
- The requested number of bytes to skipIOException
- If an error occursprotected void finalize()
Object
The finalize() method of a Class is only called if it overrides finalize() - the finalize() method java.lang.Object is never called by the Eve VM.
finalize
in class InputStream
public long getLength() throws IOException
RandomStream
getLength
in class RandomStream
IOException
- if an IO error occured.public void setLength(long length) throws IOException
RandomStream
setLength
in class RandomStream
IOException
- if the length cannot be set or if there was an error.public long getPosition() throws IOException
RandomStream
getPosition
in class RandomStream
IOException
- on error.public void setPosition(long newPosition) throws IOException
RandomStream
setPosition
in class RandomStream
newPosition
- the new position to set.IOException
- on error.public void write(int b) throws IOException
RandomStream
int
passed as the argument.
Subclasses must provide an implementation of this method.
write
in class RandomStream
b
- The byte to be written to the output stream, passed as
the low eight bits of an int
IOException
- If an error occurspublic void write(byte[] data, int offset, int count) throws IOException, NullPointerException, IndexOutOfBoundsException
RandomStream
len
bytes from the specified array
b
starting at index off
into the array.
This method in this class calls the single byte write()
method in a loop until all bytes have been written. Subclasses should
override this method if possible in order to provide a more efficent
implementation.
write
in class RandomStream
data
- The array of bytes to write fromoffset
- The index into the array to start writing fromcount
- The number of bytes to writeIOException
- If an error occursNullPointerException
IndexOutOfBoundsException
public void flush() throws IOException
RandomStream
This method in this class does nothing.
flush
in class RandomStream
IOException
- If an error occursprotected void throwCantWrite() throws IOException
RandomStream
throwCantWrite
in class RandomStream
IOException
- always thrown.