Package htsjdk.tribble.readers
Class PositionalBufferedStream
- java.lang.Object
-
- java.io.InputStream
-
- htsjdk.tribble.readers.PositionalBufferedStream
-
- All Implemented Interfaces:
LocationAware,Positional,Closeable,AutoCloseable
public final class PositionalBufferedStream extends InputStream implements Positional
A wrapper around anInputStreamwhich performs it's own buffering, and keeps track of the position. TODO: This class implements Positional, which in turn extends LocationAware, which requires preservation of virtual file pointers on BGZF inputs. However, if the inputStream wrapped by this class is a BlockCompressedInputStream, it violates that contract by wrapping the stream and returning positional file offsets instead.
-
-
Constructor Summary
Constructors Constructor Description PositionalBufferedStream(InputStream is)PositionalBufferedStream(InputStream is, int bufferSize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetPosition()The current offset, in bytes, of this stream/writer/file.booleanisDone()Is the stream done? Equivalent to ! hasNext() for an iterator?static voidmain(String[] args)intpeek()Return the next byte in the first, without actually reading it from the stream.intread()intread(byte[] bytes)intread(byte[] bytes, int start, int len)longskip(long nBytes)Skip the next nBytes in the stream.-
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, transferTo
-
-
-
-
Constructor Detail
-
PositionalBufferedStream
public PositionalBufferedStream(InputStream is)
-
PositionalBufferedStream
public PositionalBufferedStream(InputStream is, int bufferSize)
-
-
Method Detail
-
getPosition
public final long getPosition()
Description copied from interface:LocationAwareThe current offset, in bytes, of this stream/writer/file. Or, if this is an iterator/producer, the offset (in bytes) of the END of the most recently returned record (since a produced record corresponds to something that has been read already). See class javadoc for more. Note that for BGZF files, this does not represent an actually file position, but a virtual file pointer.- Specified by:
getPositionin interfaceLocationAware
-
read
public final int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public final int read(byte[] bytes, int start, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
read
public final int read(byte[] bytes) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
isDone
public final boolean isDone() throws IOExceptionDescription copied from interface:PositionalIs the stream done? Equivalent to ! hasNext() for an iterator?- Specified by:
isDonein interfacePositional- Returns:
- true if the stream has reached EOF, false otherwise
- Throws:
IOException
-
peek
public final int peek() throws IOExceptionDescription copied from interface:PositionalReturn the next byte in the first, without actually reading it from the stream. Has the same output as read()- Specified by:
peekin interfacePositional- Returns:
- the next byte, or -1 if EOF encountered
- Throws:
IOException
-
skip
public final long skip(long nBytes) throws IOExceptionDescription copied from interface:PositionalSkip the next nBytes in the stream.- Specified by:
skipin interfacePositional- Overrides:
skipin classInputStream- Parameters:
nBytes- to skip, must be >= 0- Returns:
- the number of bytes actually skippped.
- Throws:
IOException
-
close
public final void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream
-
-