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

java.lang.Object
  extended by org.apache.hadoop.hbase.io.hfile.HFile.Reader.Scanner
All Implemented Interfaces:
HFileScanner
Enclosing class:
HFile.Reader

protected static class HFile.Reader.Scanner
extends Object
implements HFileScanner


Field Summary
 int blockFetches
           
 
Constructor Summary
HFile.Reader.Scanner(HFile.Reader r, boolean cacheBlocks, boolean pread)
           
 
Method Summary
 ByteBuffer getKey()
          Gets a buffer view to the current key.
 String getKeyString()
          Convenience method to get a copy of the key as a string - interpreting the bytes as UTF8.
 KeyValue getKeyValue()
           
 HFile.Reader getReader()
           
 ByteBuffer getValue()
          Gets a buffer view to the current value.
 String getValueString()
          Convenience method to get a copy of the value as a string - interpreting the bytes as UTF8.
 boolean isSeeked()
           
 boolean next()
          Scans to the next entry in the file.
 int reseekTo(byte[] key)
          Reseek to or just before the passed key.
 int reseekTo(byte[] key, int offset, int length)
           
 boolean seekBefore(byte[] key)
          Consider the key stream of all the keys in the file, k[0] ..
 boolean seekBefore(byte[] key, int offset, int length)
           
 boolean seekTo()
          Positions this scanner at the start of the file.
 int seekTo(byte[] key)
          SeekTo or just before the passed key.
 int seekTo(byte[] key, int offset, int length)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

blockFetches

public int blockFetches
Constructor Detail

HFile.Reader.Scanner

public HFile.Reader.Scanner(HFile.Reader r,
                            boolean cacheBlocks,
                            boolean pread)
Method Detail

getKeyValue

public KeyValue getKeyValue()
Specified by:
getKeyValue in interface HFileScanner
Returns:
Instance of KeyValue.

getKey

public ByteBuffer getKey()
Description copied from interface: HFileScanner
Gets a buffer view to the current key. You must call HFileScanner.seekTo(byte[]) before this method.

Specified by:
getKey in interface HFileScanner
Returns:
byte buffer for the key. The limit is set to the key size, and the position is 0, the start of the buffer view.

getValue

public ByteBuffer getValue()
Description copied from interface: HFileScanner
Gets a buffer view to the current value. You must call HFileScanner.seekTo(byte[]) before this method.

Specified by:
getValue in interface HFileScanner
Returns:
byte buffer for the value. The limit is set to the value size, and the position is 0, the start of the buffer view.

next

public boolean next()
             throws IOException
Description copied from interface: HFileScanner
Scans to the next entry in the file.

Specified by:
next in interface HFileScanner
Returns:
Returns false if you are at the end otherwise true if more in file.
Throws:
IOException

seekTo

public int seekTo(byte[] key)
           throws IOException
Description copied from interface: HFileScanner
SeekTo or just before the passed key. Examine the return code to figure whether we found the key or not. Consider the key stream of all the keys in the file, k[0] .. k[n], where there are n keys in the file.

Specified by:
seekTo in interface HFileScanner
Parameters:
key - Key to find.
Returns:
-1, if key < k[0], no position; 0, such that k[i] = key and scanner is left in position i; and 1, such that k[i] < key, and scanner is left in position i. The scanner will position itself between k[i] and k[i+1] where k[i] < key <= k[i+1]. If there is no key k[i+1] greater than or equal to the input key, then the scanner will position itself at the end of the file and next() will return false when it is called.
Throws:
IOException

seekTo

public int seekTo(byte[] key,
                  int offset,
                  int length)
           throws IOException
Specified by:
seekTo in interface HFileScanner
Throws:
IOException

reseekTo

public int reseekTo(byte[] key)
             throws IOException
Description copied from interface: HFileScanner
Reseek to or just before the passed key. Similar to seekTo except that this can be called even if the scanner is not at the beginning of a file. This can be used to seek only to keys which come after the current position of the scanner. Consider the key stream of all the keys in the file, k[0] .. k[n], where there are n keys in the file after current position of HFileScanner. The scanner will position itself between k[i] and k[i+1] where k[i] < key <= k[i+1]. If there is no key k[i+1] greater than or equal to the input key, then the scanner will position itself at the end of the file and next() will return false when it is called.

Specified by:
reseekTo in interface HFileScanner
Parameters:
key - Key to find (should be non-null)
Returns:
-1, if key < k[0], no position; 0, such that k[i] = key and scanner is left in position i; and 1, such that k[i] < key, and scanner is left in position i.
Throws:
IOException

reseekTo

public int reseekTo(byte[] key,
                    int offset,
                    int length)
             throws IOException
Specified by:
reseekTo in interface HFileScanner
Throws:
IOException

seekBefore

public boolean seekBefore(byte[] key)
                   throws IOException
Description copied from interface: HFileScanner
Consider the key stream of all the keys in the file, k[0] .. k[n], where there are n keys in the file.

Specified by:
seekBefore in interface HFileScanner
Parameters:
key - Key to find
Returns:
false if key <= k[0] or true with scanner in position 'i' such that: k[i] < key. Furthermore: there may be a k[i+1], such that k[i] < key <= k[i+1] but there may also NOT be a k[i+1], and next() will return false (EOF).
Throws:
IOException

seekBefore

public boolean seekBefore(byte[] key,
                          int offset,
                          int length)
                   throws IOException
Specified by:
seekBefore in interface HFileScanner
Throws:
IOException

getKeyString

public String getKeyString()
Description copied from interface: HFileScanner
Convenience method to get a copy of the key as a string - interpreting the bytes as UTF8. You must call HFileScanner.seekTo(byte[]) before this method.

Specified by:
getKeyString in interface HFileScanner
Returns:
key as a string

getValueString

public String getValueString()
Description copied from interface: HFileScanner
Convenience method to get a copy of the value as a string - interpreting the bytes as UTF8. You must call HFileScanner.seekTo(byte[]) before this method.

Specified by:
getValueString in interface HFileScanner
Returns:
value as a string

getReader

public HFile.Reader getReader()
Specified by:
getReader in interface HFileScanner
Returns:
Reader that underlies this Scanner instance.

isSeeked

public boolean isSeeked()
Specified by:
isSeeked in interface HFileScanner
Returns:
True is scanner has had one of the seek calls invoked; i.e. HFileScanner.seekBefore(byte[]) or HFileScanner.seekTo() or HFileScanner.seekTo(byte[]). Otherwise returns false.

seekTo

public boolean seekTo()
               throws IOException
Description copied from interface: HFileScanner
Positions this scanner at the start of the file.

Specified by:
seekTo in interface HFileScanner
Returns:
False if empty file; i.e. a call to next would return false and the current key and value are undefined.
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


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