public abstract class SeekableInputStream extends InputStream implements Seekable
InputStream
s implementing the Seekable
interface.
SeekableOutputStream
Modifier and Type | Field and Description |
---|---|
protected Stack<Long> |
markedPositions |
Constructor and Description |
---|
SeekableInputStream() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkOpen() |
void |
close()
Closes the stream.
|
protected abstract void |
closeImpl() |
protected void |
finalize()
Finalizes this object prior to garbage collection.
|
void |
flush()
Discards the initial position of the stream prior to the current stream
position.
|
void |
flushBefore(long pPosition)
Discards the initial portion of the stream prior to the indicated
postion.
|
protected abstract void |
flushBeforeImpl(long pPosition)
Discards the initial portion of the stream prior to the indicated postion.
|
long |
getFlushedPosition()
Returns the earliest position in the stream to which seeking may be
performed.
|
long |
getStreamPosition()
Returns the current byte position of the stream.
|
void |
mark()
Marks a position in the stream to be returned to by a subsequent call to
reset.
|
void |
mark(int pLimit) |
boolean |
markSupported()
Returns
true , as marking is always supported. |
int |
read(byte[] pBytes) |
void |
reset()
Returns the file pointer to its previous position,
at the time of the most recent unmatched call to mark.
|
void |
seek(long pPosition)
Sets the current stream position to the desired location.
|
protected abstract void |
seekImpl(long pPosition) |
long |
skip(long pLength)
Implemented using
seek(currentPos + pLength) . |
available, read, read
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isCached, isCachedFile, isCachedMemory
public final int read(byte[] pBytes) throws IOException
read
in class InputStream
IOException
public final long skip(long pLength) throws IOException
seek(currentPos + pLength)
.skip
in class InputStream
pLength
- the number of bytes to skippLength
)IOException
- if an I/O exception occurs during skippublic final void mark(int pLimit)
mark
in class InputStream
public final boolean markSupported()
true
, as marking is always supported.markSupported
in class InputStream
true
.public final void seek(long pPosition) throws IOException
Seekable
IndexOutOfBoundsException
will be thrown if pPosition is smaller
than the flushed position (as returned by Seekable.getFlushedPosition()
).
It is legal to seek past the end of the file; an EOFException
will be thrown only if a read is performed.seek
in interface Seekable
pPosition
- a long containing the desired file pointer position.IOException
- if any other I/O error occurs.protected abstract void seekImpl(long pPosition) throws IOException
IOException
public final void mark()
Seekable
InputStream
, all Seekable
streams upport marking. Additionally, calls to mark
and
reset
may be nested arbitrarily.
Unlike the mark
methods declared by the Reader
or
InputStream
interfaces, no readLimit
parameter is used. An arbitrary amount
of data may be read following the call to mark
.public final void reset() throws IOException
Seekable
IOException
IOException
will be thrown if the previous marked position
lies in the discarded portion of the stream.reset
in interface Seekable
reset
in class InputStream
IOException
- if an I/O error occurs.InputStream.reset()
public final void flushBefore(long pPosition) throws IOException
Seekable
IndexOutOfBoundsException
.
Calling flushBefore
may allow classes implementing this
interface to free up resources such as memory or disk space that are
being used to store data from the stream.flushBefore
in interface Seekable
pPosition
- a long containing the length of the file prefix that
may be flushed.IOException
- if an I/O error occurs.protected abstract void flushBeforeImpl(long pPosition) throws IOException
pPosition
- the position to flush toIOException
- if an I/O exception occurs during the flush operationflushBefore(long)
public final void flush() throws IOException
Seekable
flushBefore(getStreamPosition())
.flush
in interface Seekable
IOException
- if an I/O error occurs.public final long getFlushedPosition() throws IOException
Seekable
flushBefore
.getFlushedPosition
in interface Seekable
long
.IOException
- if an I/O error occurs.public final long getStreamPosition() throws IOException
Seekable
getStreamPosition
in interface Seekable
long
containing the position of the stream.IOException
- if an I/O error occurs.protected final void checkOpen() throws IOException
IOException
public final void close() throws IOException
Seekable
close
in interface Seekable
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
- if the stream can't be closed.protected abstract void closeImpl() throws IOException
IOException
protected void finalize() throws Throwable
close
method is called to close any open input
source. This method should not be called from application
code.Copyright © 2017. All rights reserved.