htsjdk.samtools.util
Class BlockCompressedInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by htsjdk.samtools.util.BlockCompressedInputStream
All Implemented Interfaces:
LocationAware, java.io.Closeable

public class BlockCompressedInputStream
extends java.io.InputStream
implements LocationAware


Nested Class Summary
static class BlockCompressedInputStream.FileTermination
           
 
Constructor Summary
BlockCompressedInputStream(java.io.File file)
          Use this ctor if you wish to call seek()
BlockCompressedInputStream(java.io.InputStream stream)
          Note that seek() is not supported if this ctor is used.
BlockCompressedInputStream(java.io.InputStream stream, boolean allowBuffering)
          Note that seek() is not supported if this ctor is used.
BlockCompressedInputStream(SeekableStream strm)
          For providing some arbitrary data source.
BlockCompressedInputStream(java.net.URL url)
           
 
Method Summary
static void assertNonDefectiveFile(java.io.File file)
           
 int available()
           
static BlockCompressedInputStream.FileTermination checkTermination(java.io.File file)
           
 void close()
          Closes the underlying InputStream or RandomAccessFile
static long getFileBlock(long bgzfOffset)
           
 long getFilePointer()
           
 long getPosition()
          The current offset, in bytes, of this stream/writer/file.
static boolean isValidFile(java.io.InputStream stream)
           
 int read()
          Reads the next byte of data from the input stream.
 int read(byte[] buffer)
          Reads some number of bytes from the input stream and stores them into the buffer array b.
 int read(byte[] buffer, int offset, int length)
          Reads up to len bytes of data from the input stream into an array of bytes.
 java.lang.String readLine()
          Reads a whole line.
 void seek(long pos)
          Seek to the given position in the file.
 void setCheckCrcs(boolean check)
          Determines whether or not the inflater will re-calculated the CRC on the decompressed data and check it against the value stored in the GZIP header.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BlockCompressedInputStream

public BlockCompressedInputStream(java.io.InputStream stream)
Note that seek() is not supported if this ctor is used.


BlockCompressedInputStream

public BlockCompressedInputStream(java.io.InputStream stream,
                                  boolean allowBuffering)
Note that seek() is not supported if this ctor is used.


BlockCompressedInputStream

public BlockCompressedInputStream(java.io.File file)
                           throws java.io.IOException
Use this ctor if you wish to call seek()

Throws:
java.io.IOException

BlockCompressedInputStream

public BlockCompressedInputStream(java.net.URL url)

BlockCompressedInputStream

public BlockCompressedInputStream(SeekableStream strm)
For providing some arbitrary data source. No additional buffering is provided, so if the underlying source is not buffered, wrap it in a SeekableBufferedStream before passing to this ctor.

Method Detail

setCheckCrcs

public void setCheckCrcs(boolean check)
Determines whether or not the inflater will re-calculated the CRC on the decompressed data and check it against the value stored in the GZIP header. CRC checking is an expensive operation and should be used accordingly.


available

public int available()
              throws java.io.IOException
Overrides:
available in class java.io.InputStream
Returns:
the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or another thread. Note that although the next caller can read this many bytes without blocking, the available() method call itself may block in order to fill an internal buffer if it has been exhausted.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Closes the underlying InputStream or RandomAccessFile

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Reads the next byte of data from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Specified by:
read in class java.io.InputStream
Returns:
the next byte of data, or -1 if the end of the stream is reached.
Throws:
java.io.IOException

read

public int read(byte[] buffer)
         throws java.io.IOException
Reads some number of bytes from the input stream and stores them into the buffer array b. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown. read(buf) has the same effect as read(buf, 0, buf.length).

Overrides:
read in class java.io.InputStream
Parameters:
buffer - the buffer into which the data is read.
Returns:
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

readLine

public java.lang.String readLine()
                          throws java.io.IOException
Reads a whole line. A line is considered to be terminated by either a line feed ('\n'), carriage return ('\r') or carriage return followed by a line feed ("\r\n").

Returns:
A String containing the contents of the line, excluding the line terminating character, or null if the end of the stream has been reached
Throws:
java.io.IOException - If an I/O error occurs

read

public int read(byte[] buffer,
                int offset,
                int length)
         throws java.io.IOException
Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer. This method blocks until input data is available, end of file is detected, or an exception is thrown.

Overrides:
read in class java.io.InputStream
Parameters:
buffer - buffer into which data is read.
offset - the start offset in array b at which the data is written.
length - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
Throws:
java.io.IOException

seek

public void seek(long pos)
          throws java.io.IOException
Seek to the given position in the file. Note that pos is a special virtual file pointer, not an actual byte offset.

Parameters:
pos - virtual file pointer
Throws:
java.io.IOException

getFilePointer

public long getFilePointer()
Returns:
virtual file pointer that can be passed to seek() to return to the current position. This is not an actual byte offset, so arithmetic on file pointers cannot be done to determine the distance between the two.

getPosition

public 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

getFileBlock

public static long getFileBlock(long bgzfOffset)

isValidFile

public static boolean isValidFile(java.io.InputStream stream)
                           throws java.io.IOException
Parameters:
stream - Must be at start of file. Throws RuntimeException if !stream.markSupported().
Returns:
true if the given file looks like a valid BGZF file.
Throws:
java.io.IOException

checkTermination

public static BlockCompressedInputStream.FileTermination checkTermination(java.io.File file)
                                                                   throws java.io.IOException
Throws:
java.io.IOException

assertNonDefectiveFile

public static void assertNonDefectiveFile(java.io.File file)
                                   throws java.io.IOException
Throws:
java.io.IOException