Package htsjdk.samtools.seekablestream
Class SeekableStream
java.lang.Object
java.io.InputStream
htsjdk.samtools.seekablestream.SeekableStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
ByteArraySeekableStream
,SeekableBufferedStream
,SeekableFileStream
,SeekableFTPStream
,SeekableHTTPStream
,SeekableMemoryStream
,SeekablePathStream
InputStream with random access support (seek).
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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OptionalLong
If the stream is marked withmark(int)
this represents theposition()
where the stream was; otherwise, this is empty. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
The return value of this method is unusable for any purpose, and we are only implementing it because certain Java classes likeGZIPInputStream
incorrectly rely on it to detect EOFabstract void
close()
abstract boolean
eof()
abstract String
abstract long
length()
final void
mark
(int readlimit) Mark the current position of the stream.final boolean
Mark is always supported by anySeekableStream
.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.Methods inherited from class java.io.InputStream
nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, skipNBytes, transferTo
-
Field Details
-
mark
If the stream is marked withmark(int)
this represents theposition()
where the stream was; otherwise, this is empty.
-
-
Constructor Details
-
SeekableStream
public SeekableStream()
-
-
Method Details
-
length
public abstract long length()- Returns:
- the length of the stream; 0 if not available or empty.
-
position
- Returns:
- the current byte position of the stream.
- Throws:
IOException
-
seek
Seeks the stream to the provided position.- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
eof
- Returns:
true
if the stream is already consumed;false
otherwise.- Throws:
IOException
-
getSource
- Returns:
- String representation of source (e.g. URL, file path, etc.), or null if not available.
-
readFully
Read enough bytes to fill the input buffer.- Parameters:
b
-- Throws:
EOFException
- If EOF is reached before buffer is filledIOException
-
available
The return value of this method is unusable for any purpose, and we are only implementing it because certain Java classes likeGZIPInputStream
incorrectly rely on it to detect EOFIf
eof() == true
, 0 bytes are available. Otherwise, available bytes are the difference between the length of the stream (length()
) and the current position (position()
.- Overrides:
available
in classInputStream
- Returns:
0
if the end of the file has been reached or the length cannot be determined; number of bytes remaining in the stream otherwise.- Throws:
IOException
-
mark
public final void mark(int readlimit) Mark the current position of the stream.Note: there is no limit for reading.
- Overrides:
mark
in classInputStream
- Parameters:
readlimit
- ignored.- Throws:
RuntimeIOException
- if an IO error occurs other than an already closed stream.
-
reset
Seeks to the marked position if set; otherwise to the beginning of the stream.- Overrides:
reset
in classInputStream
- Throws:
IOException
-
markSupported
public final boolean markSupported()Mark is always supported by anySeekableStream
.- Overrides:
markSupported
in classInputStream
-