public class ReftableReader extends Reftable
ReftableReader
is not thread-safe. Concurrent readers need their own
instance to read from the same file.
Modifier and Type | Class and Description |
---|---|
private class |
ReftableReader.LogCursorImpl |
private class |
ReftableReader.ObjCursorImpl |
private class |
ReftableReader.RefCursorImpl |
Modifier and Type | Field and Description |
---|---|
private int |
blockSize |
(package private) static LongList |
EMPTY_LONG_LIST |
private LongMap<BlockReader> |
indexCache |
private long |
logEnd |
private BlockReader |
logIndex |
private long |
logIndexPosition |
private long |
logPosition |
private long |
maxUpdateIndex |
private long |
minUpdateIndex |
private long |
objEnd |
private int |
objIdLen |
private BlockReader |
objIndex |
private long |
objIndexPosition |
private long |
objPosition |
private long |
refEnd |
private BlockReader |
refIndex |
private long |
refIndexPosition |
private BlockSource |
src |
includeDeletes
Constructor and Description |
---|
ReftableReader(BlockSource src)
Initialize a new reftable reader.
|
Modifier and Type | Method and Description |
---|---|
LogCursor |
allLogs()
Seek reader to read log records.
|
RefCursor |
allRefs()
Seek to the first reference, to iterate in order.
|
private BlockReader |
binarySearch(byte blockType,
byte[] key,
long startPos,
long endPos) |
private int |
blocksIn(long pos,
long end) |
int |
blockSize()
Get the block size in bytes chosen for this file by the writer.
|
RefCursor |
byObjectId(AnyObjectId id)
Match references pointing to a specific object.
|
void |
close() |
private void |
initLogIndex() |
private void |
initObjIndex() |
private void |
initRefIndex() |
long |
maxUpdateIndex()
Get the maximum update index for log entries that appear in this
reftable.
|
long |
minUpdateIndex()
Get the minimum update index for log entries that appear in this
reftable.
|
private BlockReader |
readBlock(long pos,
long end) |
private int |
readBlockLen(long pos) |
private void |
readFileFooter() |
private void |
readFileHeader() |
private byte[] |
readHeaderOrFooter(long pos,
int len) |
private BlockReader |
readIndex(long pos) |
private BlockReader |
seek(byte blockType,
byte[] key,
BlockReader idx,
long startPos,
long endPos) |
LogCursor |
seekLog(java.lang.String refName,
long updateIndex)
Seek to an update index in a reference's log.
|
RefCursor |
seekRef(java.lang.String refName)
Seek to a reference.
|
RefCursor |
seekRefsWithPrefix(java.lang.String prefix)
Seek references with prefix.
|
long |
size()
Get size of the reftable, in bytes.
|
exactRef, from, hasId, hasRef, hasRefsWithPrefix, resolve, seekLog, setIncludeDeletes
private final BlockSource src
private int blockSize
private long minUpdateIndex
private long maxUpdateIndex
private long refEnd
private long objPosition
private long objEnd
private long logPosition
private long logEnd
private int objIdLen
private long refIndexPosition
private long objIndexPosition
private long logIndexPosition
private BlockReader refIndex
private BlockReader objIndex
private BlockReader logIndex
private LongMap<BlockReader> indexCache
static final LongList EMPTY_LONG_LIST
public ReftableReader(BlockSource src)
src
- the file content to read.public int blockSize() throws java.io.IOException
BlockSource
will be
aligned to the block size.java.io.IOException
- file cannot be read.public long minUpdateIndex() throws java.io.IOException
maxUpdateIndex
if this table is used in a stack.java.io.IOException
- file cannot be read.public long maxUpdateIndex() throws java.io.IOException
maxUpdateIndex
if this table is used in a stack.java.io.IOException
- file cannot be read.public RefCursor allRefs() throws java.io.IOException
public RefCursor seekRef(java.lang.String refName) throws java.io.IOException
This method will seek to the reference refName
. If present, the
returned cursor will iterate exactly one entry. If not found, an empty
cursor is returned.
public RefCursor seekRefsWithPrefix(java.lang.String prefix) throws java.io.IOException
The method will seek all the references starting with prefix
as a
prefix. If no references start with this prefix, an empty cursor is
returned.
seekRefsWithPrefix
in class Reftable
prefix
- prefix to find.java.io.IOException
- if references cannot be read.public RefCursor byObjectId(AnyObjectId id) throws java.io.IOException
byObjectId
in class Reftable
id
- object to find.java.io.IOException
- if references cannot be read.public LogCursor allLogs() throws java.io.IOException
public LogCursor seekLog(java.lang.String refName, long updateIndex) throws java.io.IOException
seekLog
in class Reftable
refName
- exact name of the reference whose log to read.updateIndex
- most recent index to return first in the log cursor. Log
records at or before updateIndex
will be returned.java.io.IOException
- if logs cannot be read.private BlockReader seek(byte blockType, byte[] key, BlockReader idx, long startPos, long endPos) throws java.io.IOException
java.io.IOException
private BlockReader binarySearch(byte blockType, byte[] key, long startPos, long endPos) throws java.io.IOException
java.io.IOException
private void readFileHeader() throws java.io.IOException
java.io.IOException
private void readFileFooter() throws java.io.IOException
java.io.IOException
private byte[] readHeaderOrFooter(long pos, int len) throws java.io.IOException
java.io.IOException
private void initRefIndex() throws java.io.IOException
java.io.IOException
private void initObjIndex() throws java.io.IOException
java.io.IOException
private void initLogIndex() throws java.io.IOException
java.io.IOException
private BlockReader readIndex(long pos) throws java.io.IOException
java.io.IOException
private int readBlockLen(long pos) throws java.io.IOException
java.io.IOException
private BlockReader readBlock(long pos, long end) throws java.io.IOException
java.io.IOException
private int blocksIn(long pos, long end)
public long size() throws java.io.IOException
java.io.IOException
- size cannot be obtained.