java.io.InputStream
that allows seeking within the input, similar to the RandomAccessFile
class. Additionally, the DataInput
interface is supported and extended to include support for little-endian representations of fundamental data types. In addition to the familiar methods from InputStream
, the methods getFilePointer()
, seek()
, are defined as in the RandomAccessFile
class. The canSeekBackwards()
method will return true
if it is permissible to seek to a position earlier in the stream than the current value of getFilePointer()
. Some subclasses of SeekableStream
guarantee the ability to seek backwards while others may not offer this feature in the interest of providing greater efficiency for those users who do not require it.
The DataInput
interface is supported as well. This included the skipBytes()
and readFully()
methods and a variety of read
methods for various data types.
Three classes are provided for the purpose of adapting a standard InputStream
to the SeekableStream
interface. ForwardSeekableStream
does not allows seeking backwards, but is inexpensive to use. FileCacheSeekableStream
maintains a copy of all of the data read from the input in a temporary file; this file will be discarded automatically when the FileSeekableStream
is finalized, or when the JVM exits normally. FileCacheSeekableStream
is intended to be reasonably efficient apart from the unavoidable use of disk space. In circumstances where the creation of a temporary file is not possible, MemoryCacheSeekableStream
may be used. MemoryCacheSeekableStream
creates a potentially large in-memory buffer to store the stream data and so should be avoided when possible.
The FileSeekableStream
class wraps a File
or RandomAccessFile
. It forwards requests to the real underlying file. It performs a limited amount of caching in order to avoid excessive I/O costs.
The SegmentedSeekableStream
class performs a different sort of function. It creates a SeekableStream
from another SeekableStream
by selecting a series of portions or "segments". Each segment starts at a specified location within the source SeekableStream
and extends for a specified number of bytes. The StreamSegmentMapper
interface and StreamSegment
class may be used to compute the segment positions dynamically.
A convenience methods, wrapInputStream
is provided to construct a suitable SeekableStream
instance whose data is supplied by a given InputStream
. The caller, by means of the canSeekBackwards
parameter, determines whether support for seeking backwards is required.
|
|
|
|
|
|