htsjdk.tribble.readers
Class PositionalBufferedStream

java.lang.Object
  extended by java.io.InputStream
      extended by htsjdk.tribble.readers.PositionalBufferedStream
All Implemented Interfaces:
LocationAware, Positional, java.io.Closeable

public final class PositionalBufferedStream
extends java.io.InputStream
implements Positional

A wrapper around an InputStream which performs it's own buffering, and keeps track of the position.


Constructor Summary
PositionalBufferedStream(java.io.InputStream is)
           
PositionalBufferedStream(java.io.InputStream is, int bufferSize)
           
 
Method Summary
 void close()
           
 long getPosition()
          The current offset, in bytes, of this stream/writer/file.
 boolean isDone()
          Is the stream done? Equivalent to ! hasNext() for an iterator?
static void main(java.lang.String[] args)
           
 int peek()
          Return the next byte in the first, without actually reading it from the stream.
 int read()
           
 int read(byte[] bytes)
           
 int read(byte[] bytes, int start, int len)
           
 long skip(long nBytes)
          Skip the next nBytes in the stream.
 
Methods inherited from class java.io.InputStream
available, mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionalBufferedStream

public PositionalBufferedStream(java.io.InputStream is)

PositionalBufferedStream

public PositionalBufferedStream(java.io.InputStream is,
                                int bufferSize)
Method Detail

getPosition

public final long getPosition()
Description copied from interface: LocationAware
The 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:
getPosition in interface LocationAware

read

public final int read()
               throws java.io.IOException
Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public final int read(byte[] bytes,
                      int start,
                      int len)
               throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

read

public final int read(byte[] bytes)
               throws java.io.IOException
Overrides:
read in class java.io.InputStream
Throws:
java.io.IOException

isDone

public final boolean isDone()
                     throws java.io.IOException
Description copied from interface: Positional
Is the stream done? Equivalent to ! hasNext() for an iterator?

Specified by:
isDone in interface Positional
Returns:
true if the stream has reached EOF, false otherwise
Throws:
java.io.IOException

peek

public final int peek()
               throws java.io.IOException
Description copied from interface: Positional
Return the next byte in the first, without actually reading it from the stream. Has the same output as read()

Specified by:
peek in interface Positional
Returns:
the next byte, or -1 if EOF encountered
Throws:
java.io.IOException

skip

public final long skip(long nBytes)
                throws java.io.IOException
Description copied from interface: Positional
Skip the next nBytes in the stream.

Specified by:
skip in interface Positional
Overrides:
skip in class java.io.InputStream
Parameters:
nBytes - to skip, must be >= 0
Returns:
the number of bytes actually skippped.
Throws:
java.io.IOException

close

public final void close()
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception