|
|||||||||
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 available for reading. |
|
int |
getCurrentPosition()
Retrieves current read position within this stream. |
|
static SharedInputStream |
getSharedInputStream(byte[] input)
Retrieves a shared input stream from byte[]. |
|
static SharedInputStream |
getSharedInputStream(InputStream input)
Retrieves a shared input stream 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)
input
- Byte array to use as underlying data buffer for this stream.
public SharedInputStream(SharedInputStream input)
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)
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)
input
- Input stream to use as source of input.
public static SharedInputStream getSharedInputStream(byte[] input)
input
- byte[] to use as source of input.
public static SharedInputStream getSharedInputStream(InputStream input, int length)
input
- Input stream 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.
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)
skip
in class InputStream
n
- Number of bytes to skip forward.
public int available() throws IOException
available
in class InputStream
IOException
- If an I/O error occurs.public SharedInputStream readInputStream()
public SharedInputStream readInputStream(int length)
length
- Number of bytes available in new stream.
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-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.