|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.InputStream
net.rim.device.api.io.SharedInputStream
public class SharedInputStream
Input stream that can share its stream data with a number of readers.
This class allows you to have multiple readers reading from one shared input stream, but allows each reader to have their own independent read position in the stream.
This class could be used to implement something like an ASN1 parser where one reader could be reading an internal SEQUENCE structure while another reader is reading from the external ASN1 stream of which the internal SEQUENCE is just a part.
Constructor Summary | ||
---|---|---|
SharedInputStream(byte[] input)
Deprecated. Use instead SharedInputStream.getSharedInputStream( byte[] input ) |
||
SharedInputStream(SharedInputStream input)
Constructs a new SharedInputStream instance on provided shared input stream. |
||
SharedInputStream(SharedInputStream input,
int length)
Deprecated. Use instead new SharedInputStream( SharedInputStream input ) and then setLength( int length ) on the new stream |
Method Summary | ||
---|---|---|
int |
available()
Retrieves number of bytes immediately available for reading. |
|
int |
getCurrentPosition()
Retrieves current read position within this stream. |
|
static SharedInputStream |
getSharedInputStream(byte[] input)
Retrieves a SharedInputStream from byte[]. |
|
static SharedInputStream |
getSharedInputStream(InputStream input)
Retrieves a SharedInputStream from provided input stream. |
|
static SharedInputStream |
getSharedInputStream(InputStream input,
int length)
Deprecated. Use instead SharedInputStream.getSharedInputStream( InputStream input ) and then setLength on the new stream. |
|
int |
peek()
Looks at the next byte in the stream without advancing the read position. |
|
int |
read()
Read next byte in the stream. |
|
int |
read(byte[] buffer,
int offset,
int length)
Reads a number of bytes from the stream. |
|
SharedInputStream |
readInputStream()
Retrieves new shared input stream built on current stream. |
|
SharedInputStream |
readInputStream(int length)
Deprecated. Use instead readInputStream() and then use setLength( int length ) on the new stream. |
|
void |
setCurrentPosition(int currentPosition)
Sets current read position within this stream. |
|
void |
setLength(int length)
Sets length for this input stream. |
|
long |
skip(long n)
Skip read position forward. |
Methods inherited from class java.io.InputStream |
---|
close, mark, markSupported, read, reset |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SharedInputStream(byte[] input)
SharedInputStream
instance on provided byte array.
input
- Byte array to use as underlying data buffer for this stream.public SharedInputStream(SharedInputStream input)
SharedInputStream
instance on provided shared input stream.
This builds a new shared input stream that shares the underlying data buffer of another shared input stream.
input
- Shared input stream whose buffer to share.public SharedInputStream(SharedInputStream input, int length)
SharedInputStream
instance on a section of provided
shared input stream.
This builds a new shared input stream that shares a section of the underlying data buffer of another shared input stream.
input
- Shared input stream whose buffer to share.length
- Section of buffer to read from starts at the provided input
stream parameter's read position, and proceeds for length bytes.Method Detail |
---|
public static SharedInputStream getSharedInputStream(InputStream input)
SharedInputStream
from provided input stream.
input
- The InputStream
to use as source of input.
SharedInputStream
reading from the provided the InputStream
.public static SharedInputStream getSharedInputStream(byte[] input)
SharedInputStream
from byte[].
input
- byte[] to use as source of input.
SharedInputStream
reading from the provided InputStream
.public static SharedInputStream getSharedInputStream(InputStream input, int length)
SharedInputStream
from section of provided InputStream
.
input
- The InputStream
to use as source of input.length
- Section of input stream to read from starts at the provided
input stream parameter's read position, and proceeds for length bytes.
SharedInputStream
reading from the provided InputStream
.public void setLength(int length)
length
- Maximum number of bytes for this input stream.public int peek() throws IOException
IOException
public int read() throws IOException
read
in class InputStream
IOException
- if an I/O error occurs.public int read(byte[] buffer, int offset, int length) throws IOException
Use this method to read a number of bytes from the stream into a buffer. This method blocks until input data is available, it detects an end of file, or an exception is thrown.
read
in class InputStream
buffer
- Buffer to contain the read bytes; must not be null.offset
- First element in the buffer parameter to receive a byte from the stream.length
- Number of bytes to read from the stream.
IOException
- If an I/O error occurs.InputStream.read()
public long skip(long n) throws IOException
skip
in class InputStream
n
- Number of bytes to skip forward.
IOException
- If an I/O error occurs.public int available() throws IOException
available
in class InputStream
IOException
- If an I/O error occurs.public SharedInputStream readInputStream()
SharedInputStream
built on current stream, using this stream's
current read position as the new stream's initial read position.public SharedInputStream readInputStream(int length)
SharedInputStream
built on a section of the current stream.
length
- Number of bytes available in new stream.
SharedInputStream
built on current stream, using this stream's
current read position as the initial read position, and extending for
a number of bytes equal to the length parameter.public int getCurrentPosition()
public void setCurrentPosition(int currentPosition)
currentPosition
- New read position to use; must be greater than
or equal to zero, or this method will throw an IllegalArgumentException
.
IllegalArgumentException
- Thrown if the value of currentPosition
is less than zero.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal