public class HFileReaderImpl extends Object implements HFileReader
HFileReader without caching. This provides the core functionality for reading HFile format data.| Modifier and Type | Field and Description |
|---|---|
protected HFileContext |
context |
protected Option<HFileDataBlock> |
currentDataBlock |
protected Option<BlockIndexEntry> |
currentDataBlockEntry |
protected HFileCursor |
cursor |
protected TreeMap<Key,BlockIndexEntry> |
dataBlockIndexEntryMap |
protected HFileInfo |
fileInfo |
protected long |
fileSize |
protected boolean |
isMetadataInitialized |
protected TreeMap<Key,BlockIndexEntry> |
metaBlockIndexEntryMap |
protected SeekableDataInputStream |
stream |
protected HFileTrailer |
trailer |
SEEK_TO_BEFORE_BLOCK_FIRST_KEY, SEEK_TO_BEFORE_FILE_FIRST_KEY, SEEK_TO_EOF, SEEK_TO_FOUND, SEEK_TO_IN_RANGE| Constructor and Description |
|---|
HFileReaderImpl(SeekableDataInputStream stream,
long fileSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
Option<KeyValue> |
getKeyValue() |
Option<ByteBuffer> |
getMetaBlock(String metaBlockName)
Gets the content of a meta block from HFile.
|
Option<byte[]> |
getMetaInfo(UTF8StringKey key)
Gets info entry from file info block of a HFile.
|
long |
getNumKeyValueEntries() |
void |
initializeMetadata()
Initializes metadata based on a HFile before other read operations.
|
HFileDataBlock |
instantiateHFileDataBlock(BlockIndexEntry blockToRead)
Creates an HFile data block.
|
boolean |
isSeeked() |
boolean |
next()
Scans to the next entry in the file.
|
boolean |
seekTo()
Positions this reader at the start of the file.
|
int |
seekTo(Key key)
seekTo or just before the passed
Key. |
protected final SeekableDataInputStream stream
protected final long fileSize
protected final HFileCursor cursor
protected boolean isMetadataInitialized
protected HFileTrailer trailer
protected HFileContext context
protected TreeMap<Key,BlockIndexEntry> dataBlockIndexEntryMap
protected TreeMap<Key,BlockIndexEntry> metaBlockIndexEntryMap
protected HFileInfo fileInfo
protected Option<BlockIndexEntry> currentDataBlockEntry
protected Option<HFileDataBlock> currentDataBlock
public HFileReaderImpl(SeekableDataInputStream stream, long fileSize)
public void initializeMetadata()
throws IOException
HFileReaderinitializeMetadata in interface HFileReaderIOException - upon read errors.public Option<byte[]> getMetaInfo(UTF8StringKey key) throws IOException
HFileReadergetMetaInfo in interface HFileReaderkey - meta key.IOException - upon read errors.public Option<ByteBuffer> getMetaBlock(String metaBlockName) throws IOException
HFileReadergetMetaBlock in interface HFileReadermetaBlockName - meta block name.IOException - upon read errors.public long getNumKeyValueEntries()
getNumKeyValueEntries in interface HFileReaderpublic int seekTo(Key key) throws IOException
HFileReaderKey. Examine the return code to figure whether we
found the key or not. Consider the key-value pairs in the file,
kv[0] .. kv[n-1], where there are n KV pairs in the file.
The position only moves forward so the caller has to make sure the keys are sorted before making multiple calls of this method.
seekTo in interface HFileReaderkey - Key to seek to.HFileReader.SEEK_TO_BEFORE_BLOCK_FIRST_KEY), such that
block_fake_first_key <= key < block_actual_first_key if there is no
exact match, and the reader is left in position at block_actual_first_key;
-1 (HFileReader.SEEK_TO_BEFORE_FILE_FIRST_KEY), if key < kv[0], the reader
is left in position 0;
0 (HFileReader.SEEK_TO_FOUND), such that kv[i].key = key and the reader is
left in position i;
1 (HFileReader.SEEK_TO_IN_RANGE), such that kv[i].key < key if there is
no exact match and the key is greater than the actual first of the data block, and
the reader is left in position i;
2 (HFileReader.SEEK_TO_EOF), if there is no KV greater than or equal to the
input key, and the reader positions itself at the end of the file and next() will
return false when it is called.IOException - upon read errors.public boolean seekTo()
throws IOException
HFileReaderseekTo in interface HFileReaderfalse if empty file; i.e. a call to next would return false and
the current key and value are undefined.IOException - upon read errors.public boolean next()
throws IOException
HFileReadernext in interface HFileReaderfalse if the current position is at the end;
otherwise true if more in file.IOException - upon read errors.public Option<KeyValue> getKeyValue() throws IOException
getKeyValue in interface HFileReaderKeyValue instance at current position.IOExceptionpublic boolean isSeeked()
isSeeked in interface HFileReadertrue if the reader has had one of the seek calls invoked; i.e.
HFileReader.seekTo() or HFileReader.seekTo(Key).
Otherwise, false.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic HFileDataBlock instantiateHFileDataBlock(BlockIndexEntry blockToRead) throws IOException
blockToRead - the block index entry to readIOException - if there's an error reading the blockCopyright © 2025 The Apache Software Foundation. All rights reserved.