|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.InputStream
com.gc.iotools.stream.base.AbstractInputStreamWrapper
com.gc.iotools.stream.is.RandomAccessInputStream
public class RandomAccessInputStream
A RandomAccessInputStream adds functionality to another input
stream-namely, the ability to buffer the input, allowing it to be read
multiple times, and to support the mark and reset
methods.
When the RandomAccessInputStream is created, an internal
Store is created. As bytes from the stream are read or skipped,
the internal store is refilled as necessary from the source
input stream. The implementation of store can be changed to fit
the application needs: cache on disk rather than in memory. The default
store implementation caches 64K in memory and then write the
content on disk.
It also adds the functionality of marking an InputStream without
specifying a mark length, thus allowing a reset after an
indefinite length of bytes has been read. Check the #mark() javadoc
for details.
Store| Field Summary | |
|---|---|
protected long |
markLimit
|
protected long |
markPosition
|
protected long |
randomAccessIsPosition
Position of read cursor in the RandomAccessInputStream. |
protected long |
sourcePosition
Position of reading in the source stream. |
protected SeekableStore |
store
|
| Fields inherited from class com.gc.iotools.stream.base.AbstractInputStreamWrapper |
|---|
closeCalled, source |
| Constructor Summary | |
|---|---|
RandomAccessInputStream(InputStream source)
|
|
RandomAccessInputStream(InputStream source,
int threshold)
Creates a RandomAccessInputStream with the specified
treshold, and saves its argument, the input stream source,
for later use. |
|
RandomAccessInputStream(InputStream source,
SeekableStore store)
|
|
| Method Summary | |
|---|---|
int |
available()
|
protected void |
closeOnce()
|
Store |
getStore()
Return the underlying store where the cache of data is kept. |
protected int |
innerRead(byte[] b,
int off,
int len)
|
void |
mark(int readLimit)
Marks the current position in this input stream. |
boolean |
markSupported()
Overrides the markSupported() method of the
InputStream class. |
void |
reset()
Repositions this stream to the position at the time the mark
method was last called on this input stream. |
void |
seek(long position)
. |
String |
toString()
Provides a String representation of the state of the stream for debugging purposes. |
| Methods inherited from class com.gc.iotools.stream.base.AbstractInputStreamWrapper |
|---|
close, read, read, skip |
| Methods inherited from class java.io.InputStream |
|---|
read |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected long sourcePosition
protected long randomAccessIsPosition
protected long markPosition
protected long markLimit
protected final SeekableStore store
| Constructor Detail |
|---|
public RandomAccessInputStream(InputStream source)
source - The underlying input stream.
public RandomAccessInputStream(InputStream source,
int threshold)
Creates a RandomAccessInputStream with the specified
treshold, and saves its argument, the input stream source,
for later use.
When data read under threshold size treshold is kept into
memory. Over this size it is placed on disk.
source - The underlying input stream.threshold - Maximum number of bytes to keep into memory.ThresholdStore
public RandomAccessInputStream(InputStream source,
SeekableStore store)
source - The underlying input stream.store - | Method Detail |
|---|
public int available()
throws IOException
available in class InputStreamIOExceptionpublic Store getStore()
public void mark(int readLimit)
Marks the current position in this input stream. A subsequent call to the reset() method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.
This method extends the original behavior of the class
InputStream allowing to use indefinite marking.
readLimit> 0 The readLimit arguments
tells this input stream to allow that many bytes to be read before the
mark position gets invalidated.readLimit == 0 Invalidate the all the current marks and
clean up the temporary files.readLimit < 0 Set up an indefinite mark: reset can
be invoked regardless on how many bytes have been read.
mark in class InputStreamreadLimit - the maximum limit of bytes that can be read before the mark
position becomes invalid. If negative allows indefinite
marking (the mark never becomes invalid).reset(),
InputStream.reset()public boolean markSupported()
markSupported() method of the
InputStream class.
markSupported in class InputStreamtrue for this kind of stream.InputStream.markSupported();
public void reset()
throws IOException
Repositions this stream to the position at the time the mark
method was last called on this input stream.
After invoking mark it can be invoked multiple times and it
always reset the stream at the previously marked position.
reset in class InputStreamIOException - if this stream has not been marked or if the mark has been
invalidated.mark(int),
InputStream.reset()
public void seek(long position)
throws IOException
IOExceptionpublic String toString()
toString in class Object
protected void closeOnce()
throws IOException
closeOnce in class AbstractInputStreamWrapperIOException
protected int innerRead(byte[] b,
int off,
int len)
throws IOException
innerRead in class AbstractInputStreamWrapperIOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||