public abstract class ExtendedInputStream
extends java.io.InputStream
ExtendedInputStream
is an input stream that can retrieve content at arbitrary positions
within the stream. The ExtendedInputStream
class includes methods that can read a certain
number of bytes from the stream or read an unspecified number of bytes. The stream keeps track of the
last byte position that was read. You can specify a position in the input stream to get to a later or earlier
position within the stream.
Although ExtendedInputStream
supports all types of storage devices, the ability to
efficiently seek within a content stream is limited to the capabilities of the underlying media, and might
not be appropriate for some types of storage devices. For example, the FileStorageArea
,
CmAdvancedStorageArea
file system storage device and content that has been cached
in the content cache are optimized to do native re-positioning of the input stream and, therefore, can
efficiently seek within a content stream.
Constructor and Description |
---|
ExtendedInputStream() |
Modifier and Type | Method and Description |
---|---|
abstract long |
position()
Returns the current position in this stream.
|
abstract void |
position(long newPosition)
Sets this input stream's position.
|
int |
read()
The standard
java.io.InputStream.read() method. |
int |
read(byte[] buffer)
The standard
java.io.InputStream.read(byte[] b) method. |
int |
readAt(long position,
byte[] b,
int offset,
int len)
Sets the input stream to the specified position, then reads up to
len
bytes of data from the input stream into an array of bytes. |
abstract long |
size()
Returns the total size of the underlying content.
|
abstract boolean |
sizeSupported()
Returns
true if this input stream can return the total size of the underlying content. |
public abstract long position() throws java.io.IOException
java.io.IOException
public abstract void position(long newPosition) throws java.io.IOException
newPosition
- A long
that specifies the offset into the stream (from the beginning of
the streamed data) at which to set the position.java.io.IOException
- If an I/O error occurs.EngineRuntimeException
- Throws EngineRuntimeException with
ExceptionCode.API_EXTENDED_STREAM_INVALID_POSITION
if the position specified is less than zero (0).public int read() throws java.io.IOException
java.io.InputStream.read()
method. Refer to the Java Platform Standard Edition
documentation for details about the use of this method.read
in class java.io.InputStream
java.io.IOException
public int read(byte[] buffer) throws java.io.IOException
java.io.InputStream.read(byte[] b)
method. Refer to the Java Platform Standard Edition
documentation for details about the use of this method.read
in class java.io.InputStream
java.io.IOException
public int readAt(long position, byte[] b, int offset, int len) throws java.io.IOException
len
bytes of data from the input stream into an array of bytes. This method attempts to
read as many as len
bytes, but a smaller number might be read. The
number of bytes read is returned as an integer.
This method blocks until input data is available, the end of the stream is detected, or an exception is thrown. This method does not close the embedded stream when the end of the file is reached.
If len
is zero (0), then no bytes are read and this method returns 0; otherwise,
this method attempts to read at least one byte. If no byte is available because the stream is at end of
file, this method returns -1; otherwise, this method reads at least one byte and stores the value into
b
.
The first byte read is stored into element b[offset], the next one into b[offset+1], and so on. The
number of bytes read is, at most, equal to len
. Let k be the number of bytes actually read;
these bytes will be stored in elements b[offset] through b[offset+k-1], leaving elements b[offset+k]
through b[offset+len-1] unaffected.
In every case, elements b[0] through b[offset] and elements b[offset+len] through b[b.length-1] are unaffected.
position
- A long
that specifies the position from which to begin reading the
input stream.b
- An array of bytes that is the buffer into which the data is read. When this method
returns, the buffer contains the specified byte array with the values between offset and
(offset+len-1) replaced by the bytes read from the current source.offset
- The byte offset in array b
at which to begin writing the
data read from the current input stream.len
- The maximum number of bytes to read from the current stream.len
is zero.java.io.IOException
- If an I/O error occurs.public abstract boolean sizeSupported()
true
if this input stream can return the total size of the underlying content.public abstract long size() throws java.io.IOException
sizeSupported()
method before
calling size()
to determine whether the input stream supports returning a size.java.io.IOException
- If an I/O error occurs.EngineRuntimeException
- Throws EngineRuntimeException with
ExceptionCode.API_EXTENDED_STREAM_SIZE_UNAVAILABLE
if this input stream does not
support returning a size (sizeSupported
returns false
).© Copyright IBM Corporation 2006, 2015. All rights reserved.