Class ObjectLoader.SmallObject

java.lang.Object
org.eclipse.jgit.lib.ObjectLoader
org.eclipse.jgit.lib.ObjectLoader.SmallObject
Enclosing class:
ObjectLoader

public static class ObjectLoader.SmallObject extends ObjectLoader
Simple loader around the cached byte array.

ObjectReader implementations can use this stream type when the object's content is small enough to be accessed as a single byte array.

  • Field Details

    • type

      private final int type
    • data

      private final byte[] data
  • Constructor Details

    • SmallObject

      public SmallObject(int type, byte[] data)
      Construct a small object loader.
      Parameters:
      type - type of the object.
      data - the object's data array. This array will be returned as-is for the getCachedBytes() method.
  • Method Details

    • getType

      public int getType()
      Description copied from class: ObjectLoader
      Get Git in pack object type
      Specified by:
      getType in class ObjectLoader
      Returns:
      Git in pack object type, see Constants.
    • getSize

      public long getSize()
      Description copied from class: ObjectLoader
      Get size of object in bytes
      Specified by:
      getSize in class ObjectLoader
      Returns:
      size of object in bytes
    • isLarge

      public boolean isLarge()
      Description copied from class: ObjectLoader
      Whether this object is too large to obtain as a byte array.
      Overrides:
      isLarge in class ObjectLoader
      Returns:
      true if this object is too large to obtain as a byte array. Objects over a certain threshold should be accessed only by their ObjectLoader.openStream() to prevent overflowing the JVM heap.
    • getCachedBytes

      public byte[] getCachedBytes()
      Description copied from class: ObjectLoader
      Obtain a reference to the (possibly cached) bytes of this object.

      This method offers direct access to the internal caches, potentially saving on data copies between the internal cache and higher level code. Callers who receive this reference must not modify its contents. Changes (if made) will affect the cache but not the repository itself.

      Specified by:
      getCachedBytes in class ObjectLoader
      Returns:
      the cached bytes of this object. Do not modify it.
    • openStream

      public ObjectStream openStream()
      Description copied from class: ObjectLoader
      Obtain an input stream to read this object's data.
      Specified by:
      openStream in class ObjectLoader
      Returns:
      a stream of this object's data. Caller must close the stream when through with it. The returned stream is buffered with a reasonable buffer size.