Class SeekableInputStream
java.lang.Object
java.io.InputStream
com.twelvemonkeys.io.SeekableInputStream
- All Implemented Interfaces:
Seekable, Closeable, AutoCloseable
- Direct Known Subclasses:
AbstractCachedSeekableStream, FileSeekableStream, RandomAccessStream.InputStreamView
Abstract base class for
InputStreams implementing the Seekable interface.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/SeekableInputStream.java#4 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean(package private) long(package private) longThe stream position in this stream -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidfinal voidclose()Closes the stream.protected abstract voidprotected voidfinalize()Finalizes this object prior to garbage collection.final voidflush()Discards the initial position of the stream prior to the current stream position.final voidflushBefore(long pPosition) Discards the initial portion of the stream prior to the indicated postion.protected abstract voidflushBeforeImpl(long pPosition) Discards the initial portion of the stream prior to the indicated postion.final longReturns the earliest position in the stream to which seeking may be performed.final longReturns the current byte position of the stream.final voidmark()Marks a position in the stream to be returned to by a subsequent call to reset.final voidmark(int pLimit) final booleanReturnstrue, as marking is always supported.final intread(byte[] pBytes) InputStream overridesfinal voidreset()Returns the file pointer to its previous position, at the time of the most recent unmatched call to mark.final voidseek(long pPosition) Seekable implementationprotected abstract voidseekImpl(long pPosition) final longskip(long pLength) Implemented usingseek(currentPos + pLength).Methods inherited from class InputStream
available, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferToMethods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Seekable
isCached, isCachedFile, isCachedMemory
-
Field Details
-
position
long positionThe stream position in this stream -
flushedPosition
long flushedPosition -
closed
boolean closed -
markedPositions
-
-
Constructor Details
-
SeekableInputStream
public SeekableInputStream()
-
-
Method Details
-
read
InputStream overrides- Overrides:
readin classInputStream- Throws:
IOException
-
skip
Implemented usingseek(currentPos + pLength).- Overrides:
skipin classInputStream- Parameters:
pLength- the number of bytes to skip- Returns:
- the actual number of bytes skipped (may be equal to or less
than
pLength) - Throws:
IOException- if an I/O exception occurs during skip
-
mark
public final void mark(int pLimit) - Overrides:
markin classInputStream
-
markSupported
public final boolean markSupported()Returnstrue, as marking is always supported.- Overrides:
markSupportedin classInputStream- Returns:
true.
-
seek
Seekable implementation- Specified by:
seekin interfaceSeekable- Parameters:
pPosition- a long containing the desired file pointer position.- Throws:
IOException- if any other I/O error occurs.
-
seekImpl
- Throws:
IOException
-
mark
public final void mark()Description copied from interface:SeekableMarks a position in the stream to be returned to by a subsequent call to reset. Unlike a standardInputStream, allSeekablestreams upport marking. Additionally, calls tomarkandresetmay be nested arbitrarily.Unlike the
markmethods declared by theReaderorInputStreaminterfaces, noreadLimitparameter is used. An arbitrary amount of data may be read following the call tomark. -
reset
Description copied from interface:SeekableReturns the file pointer to its previous position, at the time of the most recent unmatched call to mark.Calls to reset without a corresponding call to mark will either:
- throw an
IOException - or, reset to the beginning of the stream.
An
IOExceptionwill be thrown if the previous marked position lies in the discarded portion of the stream.- Specified by:
resetin interfaceSeekable- Overrides:
resetin classInputStream- Throws:
IOException- if an I/O error occurs.- See Also:
- throw an
-
flushBefore
Description copied from interface:SeekableDiscards the initial portion of the stream prior to the indicated postion. Attempting to seek to an offset within the flushed portion of the stream will result in anIndexOutOfBoundsException.Calling
flushBeforemay 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.- Specified by:
flushBeforein interfaceSeekable- Parameters:
pPosition- a long containing the length of the file prefix that may be flushed.- Throws:
IOException- if an I/O error occurs.
-
flushBeforeImpl
Discards the initial portion of the stream prior to the indicated postion.- Parameters:
pPosition- the position to flush to- Throws:
IOException- if an I/O exception occurs during the flush operation- See Also:
-
flush
Description copied from interface:SeekableDiscards the initial position of the stream prior to the current stream position. Equivalent toflushBefore(getStreamPosition()).- Specified by:
flushin interfaceSeekable- Throws:
IOException- if an I/O error occurs.
-
getFlushedPosition
Description copied from interface:SeekableReturns the earliest position in the stream to which seeking may be performed. The returned value will be the maximum of all values passed into previous calls toflushBefore.- Specified by:
getFlushedPositionin interfaceSeekable- Returns:
- the earliest legal position for seeking, as a
long. - Throws:
IOException- if an I/O error occurs.
-
getStreamPosition
Description copied from interface:SeekableReturns the current byte position of the stream. The next read will take place starting at this offset.- Specified by:
getStreamPositionin interfaceSeekable- Returns:
- a
longcontaining the position of the stream. - Throws:
IOException- if an I/O error occurs.
-
checkOpen
- Throws:
IOException
-
close
Description copied from interface:SeekableCloses the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSeekable- Overrides:
closein classInputStream- Throws:
IOException- if the stream can't be closed.
-
closeImpl
- Throws:
IOException
-
finalize
Finalizes this object prior to garbage collection. Theclosemethod is called to close any open input source. This method should not be called from application code.
-