public abstract class SeekableStream
extends java.io.InputStream
SeekableStream
provides an interface for random access support in InputStream
,
thought the implementation of seek(long)
. As a random access stream, it supports mark
by design, being able to seek to a concrete position.
Modifier and Type | Field and Description |
---|---|
protected java.util.OptionalLong |
mark
If the stream is marked with
mark(int) this represents the position()
where the stream was; otherwise, this is empty. |
Constructor and Description |
---|
SeekableStream() |
Modifier and Type | Method and Description |
---|---|
int |
available()
The return value of this method is unusable for any purpose, and we are only implementing it
because certain Java classes like
GZIPInputStream incorrectly rely on
it to detect EOF |
abstract void |
close() |
abstract boolean |
eof() |
abstract java.lang.String |
getSource() |
abstract long |
length() |
void |
mark(int readlimit)
Mark the current position of the stream.
|
boolean |
markSupported()
Mark is always supported by any
SeekableStream . |
abstract long |
position() |
abstract int |
read(byte[] buffer,
int offset,
int length) |
void |
readFully(byte[] b)
Read enough bytes to fill the input buffer.
|
void |
reset()
Seeks to the marked position if set; otherwise to the beginning of the stream.
|
abstract void |
seek(long position)
Seeks the stream to the provided position.
|
protected java.util.OptionalLong mark
mark(int)
this represents the position()
where the stream was; otherwise, this is empty.public abstract long length()
public abstract long position() throws java.io.IOException
java.io.IOException
public abstract void seek(long position) throws java.io.IOException
java.io.IOException
public abstract int read(byte[] buffer, int offset, int length) throws java.io.IOException
read
in class java.io.InputStream
java.io.IOException
public abstract void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
public abstract boolean eof() throws java.io.IOException
true
if the stream is already consumed; false
otherwise.java.io.IOException
public abstract java.lang.String getSource()
public void readFully(byte[] b) throws java.io.IOException
b
- java.io.EOFException
- If EOF is reached before buffer is filledjava.io.IOException
public int available() throws java.io.IOException
GZIPInputStream
incorrectly rely on
it to detect EOF
If eof() == true
, 0 bytes are available. Otherwise, available bytes are the
difference between the length of the stream (length()
) and the current position
(position()
.
available
in class java.io.InputStream
0
if the end of the file has been reached or the length cannot be determined;
number of bytes remaining in the stream otherwise.java.io.IOException
public final void mark(int readlimit)
Note: there is no limit for reading.
mark
in class java.io.InputStream
readlimit
- ignored.RuntimeIOException
- if an IO error occurs other than an already closed stream.public void reset() throws java.io.IOException
reset
in class java.io.InputStream
java.io.IOException
public final boolean markSupported()
SeekableStream
.markSupported
in class java.io.InputStream