org.apache.hadoop.hbase.io.hfile
Class HFile.Reader

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFile.Reader
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
HalfHFileReader
Enclosing class:
HFile

public static class HFile.Reader
extends Object
implements Closeable

HFile Reader.


Field Summary
 int blockLoads
           
 int cacheHits
           
 
Constructor Summary
HFile.Reader(org.apache.hadoop.fs.FileSystem fs, org.apache.hadoop.fs.Path path, BlockCache cache, boolean inMemory)
          Opens a HFile.
HFile.Reader(org.apache.hadoop.fs.FSDataInputStream fsdis, long size, BlockCache cache, boolean inMemory)
          Opens a HFile.
 
Method Summary
protected  int blockContainingKey(byte[] key, int offset, int length)
           
 void close()
           
 org.apache.hadoop.io.RawComparator<byte[]> getComparator()
           
 int getEntries()
           
 byte[] getFirstKey()
           
 byte[] getLastKey()
           
 ByteBuffer getMetaBlock(String metaBlockName)
           
 HFileScanner getScanner()
          Create a Scanner on this file.
 HFileScanner getScanner(boolean cacheBlocks)
          Create a Scanner on this file.
 String getTrailerInfo()
           
 long indexSize()
           
 boolean inMemory()
           
 long length()
           
 Map<byte[],byte[]> loadFileInfo()
          Read in the index and file info.
 byte[] midkey()
           
 String toString()
           
protected  String toStringFirstKey()
           
protected  String toStringLastKey()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cacheHits

public int cacheHits

blockLoads

public int blockLoads
Constructor Detail

HFile.Reader

public HFile.Reader(org.apache.hadoop.fs.FileSystem fs,
                    org.apache.hadoop.fs.Path path,
                    BlockCache cache,
                    boolean inMemory)
             throws IOException
Opens a HFile. You must load the file info before you can use it by calling loadFileInfo().

Parameters:
fs - filesystem to load from
path - path within said filesystem
cache - block cache. Pass null if none.
Throws:
IOException

HFile.Reader

public HFile.Reader(org.apache.hadoop.fs.FSDataInputStream fsdis,
                    long size,
                    BlockCache cache,
                    boolean inMemory)
Opens a HFile. You must load the index before you can use it by calling loadFileInfo().

Parameters:
fsdis - input stream. Caller is responsible for closing the passed stream.
size - Length of the stream.
cache - block cache. Pass null if none.
Throws:
IOException
Method Detail

toString

public String toString()
Overrides:
toString in class Object

toStringFirstKey

protected String toStringFirstKey()

toStringLastKey

protected String toStringLastKey()

length

public long length()

inMemory

public boolean inMemory()

loadFileInfo

public Map<byte[],byte[]> loadFileInfo()
                                throws IOException
Read in the index and file info.

Returns:
A map of fileinfo data. See HFile.Writer.appendFileInfo(byte[], byte[]).
Throws:
IOException

getScanner

public HFileScanner getScanner()
Create a Scanner on this file. No seeks or reads are done on creation. Call HFileScanner.seekTo(byte[]) to position an start the read. There is nothing to clean up in a Scanner. Letting go of your references to the scanner is sufficient.

Returns:
Scanner on this file.

getScanner

public HFileScanner getScanner(boolean cacheBlocks)
Create a Scanner on this file. No seeks or reads are done on creation. Call HFileScanner.seekTo(byte[]) to position an start the read. There is nothing to clean up in a Scanner. Letting go of your references to the scanner is sufficient.

Returns:
Scanner on this file.

blockContainingKey

protected int blockContainingKey(byte[] key,
                                 int offset,
                                 int length)
Parameters:
key - Key to search.
Returns:
Block number of the block containing the key or -1 if not in this file.

getMetaBlock

public ByteBuffer getMetaBlock(String metaBlockName)
                        throws IOException
Parameters:
metaBlockName -
Returns:
Block wrapped in a ByteBuffer
Throws:
IOException

getFirstKey

public byte[] getFirstKey()
Returns:
First key in the file. May be null if file has no entries.

getEntries

public int getEntries()

getLastKey

public byte[] getLastKey()
Returns:
Last key in the file. May be null if file has no entries.

getComparator

public org.apache.hadoop.io.RawComparator<byte[]> getComparator()
Returns:
Comparator.

indexSize

public long indexSize()
Returns:
index size

midkey

public byte[] midkey()
              throws IOException
Returns:
Midkey for this file. We work with block boundaries only so returned midkey is an approximation only.
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException

getTrailerInfo

public String getTrailerInfo()


Copyright © 2009 The Apache Software Foundation