Closeable, AutoCloseableByteArraySeekableStream, SeekableBufferedStream, SeekableFileStream, SeekableFTPStream, SeekableHTTPStream, SeekableMemoryStream, SeekablePathStreampublic 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, transferToprotected 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
IOExceptionpublic abstract void seek(long position)
throws IOException
IOExceptionpublic abstract int read(byte[] buffer,
int offset,
int length)
throws IOException
read in class InputStreamIOExceptionpublic abstract void close()
throws IOException
close in interface AutoCloseableclose in interface Closeableclose in class InputStreamIOExceptionpublic abstract boolean eof()
throws IOException
true if the stream is already consumed; false otherwise.IOExceptionpublic abstract String getSource()
public void readFully(byte[] b)
throws IOException
b - EOFException - If EOF is reached before buffer is filledIOExceptionpublic 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 InputStream0 if the end of the file has been reached or the length cannot be determined;
number of bytes remaining in the stream otherwise.IOExceptionpublic final void mark(int readlimit)
Note: there is no limit for reading.
mark in class InputStreamreadlimit - ignored.RuntimeIOException - if an IO error occurs other than an already closed stream.public void reset()
throws IOException
reset in class InputStreamIOExceptionpublic final boolean markSupported()
SeekableStream.markSupported in class InputStream