org.apache.hadoop.hbase.io.hfile
Class HFileBlock.AbstractFSReader

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFileBlock.AbstractFSReader
All Implemented Interfaces:
HFileBlock.FSReader
Direct Known Subclasses:
HFileBlock.FSReaderV1, HFileBlock.FSReaderV2
Enclosing class:
HFileBlock

public abstract static class HFileBlock.AbstractFSReader
extends Object
implements HFileBlock.FSReader

A common implementation of some methods of HFileBlock.FSReader and some tools for implementing HFile format version-specific block readers.


Field Summary
protected  Compression.Algorithm compressAlgo
          Compression algorithm used by the HFile
static int DEFAULT_BUFFER_SIZE
          The default buffer size for our buffered streams
protected  long fileSize
          The size of the file we are reading from, or -1 if unknown.
protected  org.apache.hadoop.fs.FSDataInputStream istream
          The file system stream of the underlying HFile
 
Constructor Summary
HFileBlock.AbstractFSReader(org.apache.hadoop.fs.FSDataInputStream istream, Compression.Algorithm compressAlgo, long fileSize)
           
 
Method Summary
 HFileBlock.BlockIterator blockRange(long startOffset, long endOffset)
          Creates a block iterator over the given portion of the HFile.
protected  InputStream createBufferedBoundedStream(long offset, int size, boolean pread)
          Creates a buffered stream reading a certain slice of the file system input stream.
protected  void decompress(byte[] dest, int destOffset, InputStream bufferedBoundedStream, int compressedSize, int uncompressedSize)
          Decompresses data from the given stream using the configured compression algorithm.
protected  int readAtOffset(byte[] dest, int destOffset, int size, boolean peekIntoNextBlock, long fileOffset, boolean pread)
          Does a positional read or a seek and read into the given buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.hadoop.hbase.io.hfile.HFileBlock.FSReader
readBlockData
 

Field Detail

istream

protected org.apache.hadoop.fs.FSDataInputStream istream
The file system stream of the underlying HFile


compressAlgo

protected Compression.Algorithm compressAlgo
Compression algorithm used by the HFile


fileSize

protected long fileSize
The size of the file we are reading from, or -1 if unknown.


DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
The default buffer size for our buffered streams

See Also:
Constant Field Values
Constructor Detail

HFileBlock.AbstractFSReader

public HFileBlock.AbstractFSReader(org.apache.hadoop.fs.FSDataInputStream istream,
                                   Compression.Algorithm compressAlgo,
                                   long fileSize)
Method Detail

blockRange

public HFileBlock.BlockIterator blockRange(long startOffset,
                                           long endOffset)
Description copied from interface: HFileBlock.FSReader
Creates a block iterator over the given portion of the HFile. The iterator returns blocks starting with offset such that offset <= startOffset < endOffset.

Specified by:
blockRange in interface HFileBlock.FSReader
Parameters:
startOffset - the offset of the block to start iteration with
endOffset - the offset to end iteration at (exclusive)
Returns:
an iterator of blocks between the two given offsets

readAtOffset

protected int readAtOffset(byte[] dest,
                           int destOffset,
                           int size,
                           boolean peekIntoNextBlock,
                           long fileOffset,
                           boolean pread)
                    throws IOException
Does a positional read or a seek and read into the given buffer. Returns the on-disk size of the next block, or -1 if it could not be determined.

Parameters:
dest - destination buffer
destOffset - offset in the destination buffer
size - size of the block to be read
peekIntoNextBlock - whether to read the next block's on-disk size
fileOffset - position in the stream to read at
pread - whether we should do a positional read
Returns:
the on-disk size of the next block with header size included, or -1 if it could not be determined
Throws:
IOException

decompress

protected void decompress(byte[] dest,
                          int destOffset,
                          InputStream bufferedBoundedStream,
                          int compressedSize,
                          int uncompressedSize)
                   throws IOException
Decompresses data from the given stream using the configured compression algorithm.

Parameters:
dest -
destOffset -
bufferedBoundedStream - a stream to read compressed data from, bounded to the exact amount of compressed data
compressedSize - compressed data size, header not included
uncompressedSize - uncompressed data size, header not included
Throws:
IOException

createBufferedBoundedStream

protected InputStream createBufferedBoundedStream(long offset,
                                                  int size,
                                                  boolean pread)
Creates a buffered stream reading a certain slice of the file system input stream. We need this because the decompression we use seems to expect the input stream to be bounded.

Parameters:
offset - the starting file offset the bounded stream reads from
size - the size of the segment of the file the stream should read
pread - whether to use position reads
Returns:
a stream restricted to the given portion of the file


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.