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
public abstract class SeekableStream extends InputStream
InputStream with random access support (seek).SeekableStreamprovides an interface for random access support inInputStream, thought the implementation ofseek(long). As a random access stream, it supports mark by design, being able to seek to a concrete position.
-
-
Field Summary
Fields Modifier and Type Field Description protected OptionalLongmarkIf the stream is marked withmark(int)this represents theposition()where the stream was; otherwise, this is empty.
-
Constructor Summary
Constructors Constructor Description SeekableStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intavailable()The return value of this method is unusable for any purpose, and we are only implementing it because certain Java classes likeGZIPInputStreamincorrectly rely on it to detect EOFabstract voidclose()abstract booleaneof()abstract StringgetSource()abstract longlength()voidmark(int readlimit)Mark the current position of the stream.booleanmarkSupported()Mark is always supported by anySeekableStream.abstract longposition()abstract intread(byte[] buffer, int offset, int length)voidreadFully(byte[] b)Read enough bytes to fill the input buffer.voidreset()Seeks to the marked position if set; otherwise to the beginning of the stream.abstract voidseek(long position)Seeks the stream to the provided position.-
Methods inherited from class java.io.InputStream
nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Field Detail
-
mark
protected OptionalLong mark
If the stream is marked withmark(int)this represents theposition()where the stream was; otherwise, this is empty.
-
-
Method Detail
-
length
public abstract long length()
- Returns:
- the length of the stream; 0 if not available or empty.
-
position
public abstract long position() throws IOException- Returns:
- the current byte position of the stream.
- Throws:
IOException
-
seek
public abstract void seek(long position) throws IOExceptionSeeks the stream to the provided position.- Throws:
IOException
-
read
public abstract int read(byte[] buffer, int offset, int length) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
close
public abstract void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
eof
public abstract boolean eof() throws IOException- Returns:
trueif the stream is already consumed;falseotherwise.- Throws:
IOException
-
getSource
public abstract String getSource()
- Returns:
- String representation of source (e.g. URL, file path, etc.), or null if not available.
-
readFully
public void readFully(byte[] b) throws IOExceptionRead enough bytes to fill the input buffer.- Parameters:
b-- Throws:
EOFException- If EOF is reached before buffer is filledIOException
-
available
public int available() throws IOExceptionThe return value of this method is unusable for any purpose, and we are only implementing it because certain Java classes likeGZIPInputStreamincorrectly 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:
availablein classInputStream- Returns:
0if 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:
markin classInputStream- Parameters:
readlimit- ignored.- Throws:
RuntimeIOException- if an IO error occurs other than an already closed stream.
-
reset
public void reset() throws IOExceptionSeeks to the marked position if set; otherwise to the beginning of the stream.- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public final boolean markSupported()
Mark is always supported by anySeekableStream.- Overrides:
markSupportedin classInputStream
-
-