Class ObjectReader

    • Field Detail

      • OBJ_ANY

        public static final int OBJ_ANY
        Type hint indicating the caller doesn't know the type.
        See Also:
        Constant Field Values
      • streamFileThreshold

        protected int streamFileThreshold
        The threshold at which a file will be streamed rather than loaded entirely into memory.
        Since:
        4.6
    • Constructor Detail

      • ObjectReader

        public ObjectReader()
    • Method Detail

      • newReader

        public abstract ObjectReader newReader()
        Construct a new reader from the same data.

        Applications can use this method to build a new reader from the same data source, but for an different thread.

        Returns:
        a brand new reader, using the same data source.
      • abbreviate

        public AbbreviatedObjectId abbreviate​(AnyObjectId objectId)
                                       throws IOException
        Obtain a unique abbreviation (prefix) of an object SHA-1. This method uses a reasonable default for the minimum length. Callers who don't care about the minimum length should prefer this method. The returned abbreviation would expand back to the argument ObjectId when passed to resolve(AbbreviatedObjectId), assuming no new objects are added to this repository between calls.
        Parameters:
        objectId - object identity that needs to be abbreviated.
        Returns:
        SHA-1 abbreviation.
        Throws:
        IOException - the object store cannot be read.
      • abbreviate

        public AbbreviatedObjectId abbreviate​(AnyObjectId objectId,
                                              int len)
                                       throws IOException
        Obtain a unique abbreviation (prefix) of an object SHA-1. The returned abbreviation would expand back to the argument ObjectId when passed to resolve(AbbreviatedObjectId), assuming no new objects are added to this repository between calls. The default implementation of this method abbreviates the id to the minimum length, then resolves it to see if there are multiple results. When multiple results are found, the length is extended by 1 and resolve is tried again.
        Parameters:
        objectId - object identity that needs to be abbreviated.
        len - minimum length of the abbreviated string. Must be in the range [2, 40].
        Returns:
        SHA-1 abbreviation. If no matching objects exist in the repository, the abbreviation will match the minimum length.
        Throws:
        IOException - the object store cannot be read.
      • resolve

        public abstract Collection<ObjectId> resolve​(AbbreviatedObjectId id)
                                              throws IOException
        Resolve an abbreviated ObjectId to its full form. This method searches for an ObjectId that begins with the abbreviation, and returns at least some matching candidates. If the returned collection is empty, no objects start with this abbreviation. The abbreviation doesn't belong to this repository, or the repository lacks the necessary objects to complete it. If the collection contains exactly one member, the abbreviation is (currently) unique within this database. There is a reasonably high probability that the returned id is what was previously abbreviated. If the collection contains 2 or more members, the abbreviation is not unique. In this case the implementation is only required to return at least 2 candidates to signal the abbreviation has conflicts. User friendly implementations should return as many candidates as reasonably possible, as the caller may be able to disambiguate further based on context. However since databases can be very large (e.g. 10 million objects) returning 625,000 candidates for the abbreviation "0" is simply unreasonable, so implementors should draw the line at around 256 matches.
        Parameters:
        id - abbreviated id to resolve to a complete identity. The abbreviation must have a length of at least 2.
        Returns:
        candidates that begin with the abbreviated identity.
        Throws:
        IOException - the object store cannot be read.
      • has

        public boolean has​(AnyObjectId objectId)
                    throws IOException
        Does the requested object exist in this database?
        Parameters:
        objectId - identity of the object to test for existence of.
        Returns:
        true if the specified object is stored in this database.
        Throws:
        IOException - the object store cannot be accessed.
      • has

        public boolean has​(AnyObjectId objectId,
                           int typeHint)
                    throws IOException
        Does the requested object exist in this database?
        Parameters:
        objectId - identity of the object to test for existence of.
        typeHint - hint about the type of object being requested, e.g. Constants.OBJ_BLOB; OBJ_ANY if the object type is not known, or does not matter to the caller.
        Returns:
        true if the specified object is stored in this database.
        Throws:
        IncorrectObjectTypeException - typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
        IOException - the object store cannot be accessed.
      • getShallowCommits

        public abstract Set<ObjectId> getShallowCommits()
                                                 throws IOException
        Returns IDs for those commits which should be considered as shallow.
        Returns:
        IDs of shallow commits
        Throws:
        IOException
      • open

        public <T extends ObjectIdAsyncObjectLoaderQueue<T> open​(Iterable<T> objectIds,
                                                                   boolean reportMissing)
        Asynchronous object opening.
        Parameters:
        objectIds - objects to open from the object store. The supplied collection must not be modified until the queue has finished.
        reportMissing - if true missing objects are reported by calling failure with a MissingObjectException. This may be more expensive for the implementation to guarantee. If false the implementation may choose to report MissingObjectException, or silently skip over the object with no warning.
        Returns:
        queue to read the objects from.
      • getObjectSize

        public long getObjectSize​(AnyObjectId objectId,
                                  int typeHint)
                           throws MissingObjectException,
                                  IncorrectObjectTypeException,
                                  IOException
        Get only the size of an object.

        The default implementation of this method opens an ObjectLoader. Databases are encouraged to override this if a faster access method is available to them.

        Parameters:
        objectId - identity of the object to open.
        typeHint - hint about the type of object being requested, e.g. Constants.OBJ_BLOB; OBJ_ANY if the object type is not known, or does not matter to the caller.
        Returns:
        size of object in bytes.
        Throws:
        MissingObjectException - the object does not exist.
        IncorrectObjectTypeException - typeHint was not OBJ_ANY, and the object's actual type does not match typeHint.
        IOException - the object store cannot be accessed.
      • getObjectSize

        public <T extends ObjectIdAsyncObjectSizeQueue<T> getObjectSize​(Iterable<T> objectIds,
                                                                          boolean reportMissing)
        Asynchronous object size lookup.
        Parameters:
        objectIds - objects to get the size of from the object store. The supplied collection must not be modified until the queue has finished.
        reportMissing - if true missing objects are reported by calling failure with a MissingObjectException. This may be more expensive for the implementation to guarantee. If false the implementation may choose to report MissingObjectException, or silently skip over the object with no warning.
        Returns:
        queue to read object sizes from.
      • setAvoidUnreachableObjects

        public void setAvoidUnreachableObjects​(boolean avoid)
        Advise the reader to avoid unreachable objects.

        While enabled the reader will skip over anything previously proven to be unreachable. This may be dangerous in the face of concurrent writes.

        Parameters:
        avoid - true to avoid unreachable objects.
        Since:
        3.0
      • getBitmapIndex

        public BitmapIndex getBitmapIndex()
                                   throws IOException
        An index that can be used to speed up ObjectWalks.
        Returns:
        the index or null if one does not exist.
        Throws:
        IOException - when the index fails to load
        Since:
        3.0
      • createReachabilityChecker

        @NonNull
        public ReachabilityChecker createReachabilityChecker​(RevWalk rw)
                                                      throws IOException
        Create a reachability checker that will use bitmaps if possible.
        Parameters:
        rw - revwalk for use by the reachability checker
        Returns:
        the most efficient reachability checker for this repository.
        Throws:
        IOException - if it cannot open any of the underlying indices.
        Since:
        5.11
      • createObjectReachabilityChecker

        @NonNull
        public ObjectReachabilityChecker createObjectReachabilityChecker​(ObjectWalk ow)
                                                                  throws IOException
        Create an object reachability checker that will use bitmaps if possible. This reachability checker accepts any object as target. For checks exclusively between commits, use createReachabilityChecker(RevWalk).
        Parameters:
        ow - objectwalk for use by the reachability checker
        Returns:
        the most efficient object reachability checker for this repository.
        Throws:
        IOException - if it cannot open any of the underlying indices.
        Since:
        5.11
      • getCreatedFromInserter

        @Nullable
        public ObjectInserter getCreatedFromInserter()
        Get the ObjectInserter from which this reader was created using inserter.newReader()
        Returns:
        the ObjectInserter from which this reader was created using inserter.newReader(), or null if this reader was not created from an inserter.
        Since:
        4.4
      • close

        public abstract void close()

        Release any resources used by this reader.

        A reader that has been released can be used again, but may need to be released after the subsequent usage.

        Specified by:
        close in interface AutoCloseable
        Since:
        4.0
      • setStreamFileThreshold

        public void setStreamFileThreshold​(int threshold)
        Sets the threshold at which a file will be streamed rather than loaded entirely into memory
        Parameters:
        threshold - the new threshold
        Since:
        4.6
      • getStreamFileThreshold

        public int getStreamFileThreshold()
        Returns the threshold at which a file will be streamed rather than loaded entirely into memory
        Returns:
        the threshold in bytes
        Since:
        4.6