Class ReftableReader

java.lang.Object
org.eclipse.jgit.internal.storage.reftable.Reftable
org.eclipse.jgit.internal.storage.reftable.ReftableReader
All Implemented Interfaces:
AutoCloseable

public class ReftableReader extends Reftable implements AutoCloseable
Reads a reftable formatted file.

ReftableReader is not thread-safe. Concurrent readers need their own instance to read from the same file.

  • Field Details

    • src

      private final BlockSource src
    • blockSize

      private int blockSize
    • minUpdateIndex

      private long minUpdateIndex
    • maxUpdateIndex

      private long maxUpdateIndex
    • refEnd

      private long refEnd
    • objPosition

      private long objPosition
    • objEnd

      private long objEnd
    • logPosition

      private long logPosition
    • logEnd

      private long logEnd
    • objIdLen

      private int objIdLen
    • refIndexPosition

      private long refIndexPosition
    • objIndexPosition

      private long objIndexPosition
    • logIndexPosition

      private long logIndexPosition
    • refIndex

      private BlockReader refIndex
    • objIndex

      private BlockReader objIndex
    • logIndex

      private BlockReader logIndex
    • indexCache

      private LongMap<BlockReader> indexCache
    • EMPTY_LONG_LIST

      static final LongList EMPTY_LONG_LIST
  • Constructor Details

    • ReftableReader

      public ReftableReader(BlockSource src)
      Initialize a new reftable reader.
      Parameters:
      src - the file content to read.
  • Method Details

    • blockSize

      public int blockSize() throws IOException
      Get the block size in bytes chosen for this file by the writer.
      Returns:
      the block size in bytes chosen for this file by the writer. Most reads from the BlockSource will be aligned to the block size.
      Throws:
      IOException - file cannot be read.
    • hasObjectMap

      public boolean hasObjectMap() throws IOException
      Specified by:
      hasObjectMap in class Reftable
      Returns:
      whether this reftable can do a fast SHA1 => ref lookup.
      Throws:
      IOException - on I/O problems.
    • minUpdateIndex

      public long minUpdateIndex() throws IOException
      Get the minimum update index for ref entries that appear in this reftable.
      Specified by:
      minUpdateIndex in class Reftable
      Returns:
      the minimum update index for ref entries that appear in this reftable.
      Throws:
      IOException - file cannot be read.
    • maxUpdateIndex

      public long maxUpdateIndex() throws IOException
      Get the maximum update index for ref entries that appear in this reftable.
      Specified by:
      maxUpdateIndex in class Reftable
      Returns:
      the maximum update index for ref entries that appear in this reftable.
      Throws:
      IOException - file cannot be read.
    • allRefs

      public RefCursor allRefs() throws IOException
      Seek to the first reference, to iterate in order.
      Specified by:
      allRefs in class Reftable
      Returns:
      cursor to iterate.
      Throws:
      IOException - if references cannot be read.
    • seekRef

      public RefCursor seekRef(String refName) throws IOException
      Seek to a reference.

      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.

      Specified by:
      seekRef in class Reftable
      Parameters:
      refName - reference name.
      Returns:
      cursor to iterate; empty cursor if no references match.
      Throws:
      IOException - if references cannot be read.
    • seekRefsWithPrefix

      public RefCursor seekRefsWithPrefix(String prefix) throws IOException
      Seek references with prefix.

      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.

      Specified by:
      seekRefsWithPrefix in class Reftable
      Parameters:
      prefix - prefix to find.
      Returns:
      cursor to iterate; empty cursor if no references match.
      Throws:
      IOException - if references cannot be read.
    • byObjectId

      public RefCursor byObjectId(AnyObjectId id) throws IOException
      Match references pointing to a specific object.
      Specified by:
      byObjectId in class Reftable
      Parameters:
      id - object to find.
      Returns:
      cursor to iterate; empty cursor if no references match.
      Throws:
      IOException - if references cannot be read.
    • allLogs

      public LogCursor allLogs() throws IOException
      Seek reader to read log records.
      Specified by:
      allLogs in class Reftable
      Returns:
      cursor to iterate; empty cursor if no logs are present.
      Throws:
      IOException - if logs cannot be read.
    • seekLog

      public LogCursor seekLog(String refName, long updateIndex) throws IOException
      Seek to an update index in a reference's log.
      Specified by:
      seekLog in class Reftable
      Parameters:
      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.
      Returns:
      cursor to iterate; empty cursor if no logs match.
      Throws:
      IOException - if logs cannot be read.
    • seek

      private BlockReader seek(byte blockType, byte[] key, BlockReader idx, long startPos, long endPos) throws IOException
      Throws:
      IOException
    • binarySearch

      private BlockReader binarySearch(byte blockType, byte[] key, long startPos, long endPos) throws IOException
      Throws:
      IOException
    • readFileHeader

      private void readFileHeader() throws IOException
      Throws:
      IOException
    • readFileFooter

      private void readFileFooter() throws IOException
      Throws:
      IOException
    • readHeaderOrFooter

      private byte[] readHeaderOrFooter(long pos, int len) throws IOException
      Throws:
      IOException
    • initRefIndex

      private void initRefIndex() throws IOException
      Throws:
      IOException
    • initObjIndex

      private void initObjIndex() throws IOException
      Throws:
      IOException
    • initLogIndex

      private void initLogIndex() throws IOException
      Throws:
      IOException
    • readIndex

      private BlockReader readIndex(long pos) throws IOException
      Throws:
      IOException
    • readBlockLen

      private int readBlockLen(long pos) throws IOException
      Throws:
      IOException
    • readBlock

      private BlockReader readBlock(long pos, long end) throws IOException
      Throws:
      IOException
    • blocksIn

      private int blocksIn(long pos, long end)
    • size

      public long size() throws IOException
      Get size of the reftable, in bytes.
      Returns:
      size of the reftable, in bytes.
      Throws:
      IOException - size cannot be obtained.
    • close

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