Closeable
, AutoCloseable
ByteArraySeekableStream
, SeekableBufferedStream
, SeekableFileStream
, SeekableFTPStream
, SeekableHTTPStream
, SeekableMemoryStream
, SeekablePathStream
public abstract class SeekableStream extends 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 | Description |
---|---|---|
protected OptionalLong |
mark |
If the stream is marked with
mark(int) this represents the position()
where the stream was; otherwise, this is empty. |
Constructor | Description |
---|---|
SeekableStream() |
Modifier and Type | Method | 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 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.
|
read, read, readAllBytes, readNBytes, skip, transferTo
protected 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 IOException
IOException
public abstract void seek(long position) throws IOException
IOException
public abstract int read(byte[] buffer, int offset, int length) throws IOException
read
in class InputStream
IOException
public abstract void close() throws IOException
close
in interface AutoCloseable
close
in interface Closeable
close
in class InputStream
IOException
public abstract boolean eof() throws IOException
true
if the stream is already consumed; false
otherwise.IOException
public abstract String getSource()
public void readFully(byte[] b) throws IOException
b
- EOFException
- If EOF is reached before buffer is filledIOException
public int available() throws 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 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.IOException
public final void mark(int readlimit)
Note: there is no limit for reading.
mark
in class InputStream
readlimit
- ignored.RuntimeIOException
- if an IO error occurs other than an already closed stream.public void reset() throws IOException
reset
in class InputStream
IOException
public final boolean markSupported()
SeekableStream
.markSupported
in class InputStream