PackedObjectInfo.java

  1. /*
  2.  * Copyright (C) 2008-2009, Robin Rosenberg <robin.rosenberg@dewire.com>
  3.  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
  4.  *
  5.  * This program and the accompanying materials are made available under the
  6.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  7.  * https://www.eclipse.org/org/documents/edl-v10.php.
  8.  *
  9.  * SPDX-License-Identifier: BSD-3-Clause
  10.  */

  11. package org.eclipse.jgit.transport;

  12. import org.eclipse.jgit.lib.AnyObjectId;
  13. import org.eclipse.jgit.lib.Constants;
  14. import org.eclipse.jgit.lib.ObjectIdOwnerMap;

  15. /**
  16.  * Description of an object stored in a pack file, including offset.
  17.  * <p>
  18.  * When objects are stored in packs Git needs the ObjectId and the offset
  19.  * (starting position of the object data) to perform random-access reads of
  20.  * objects from the pack. This extension of ObjectId includes the offset.
  21.  */
  22. public class PackedObjectInfo extends ObjectIdOwnerMap.Entry {
  23.     private long offset;

  24.     private int crc;

  25.     private int type = Constants.OBJ_BAD;

  26.     private long sizeBeforeInflating;

  27.     private long fullSize;

  28.     PackedObjectInfo(final long headerOffset, final int packedCRC,
  29.             final AnyObjectId id) {
  30.         super(id);
  31.         offset = headerOffset;
  32.         crc = packedCRC;
  33.     }

  34.     /**
  35.      * Create a new structure to remember information about an object.
  36.      *
  37.      * @param id
  38.      *            the identity of the object the new instance tracks.
  39.      */
  40.     public PackedObjectInfo(AnyObjectId id) {
  41.         super(id);
  42.     }

  43.     /**
  44.      * Get offset in pack when object has been already written
  45.      *
  46.      * @return offset in pack when object has been already written, or 0 if it
  47.      *         has not been written yet
  48.      */
  49.     public long getOffset() {
  50.         return offset;
  51.     }

  52.     /**
  53.      * Set the offset in pack when object has been written to.
  54.      *
  55.      * @param offset
  56.      *            offset where written object starts
  57.      */
  58.     public void setOffset(long offset) {
  59.         this.offset = offset;
  60.     }

  61.     /**
  62.      * Get the 32 bit CRC checksum for the packed data.
  63.      *
  64.      * @return the 32 bit CRC checksum for the packed data.
  65.      */
  66.     public int getCRC() {
  67.         return crc;
  68.     }

  69.     /**
  70.      * Record the 32 bit CRC checksum for the packed data.
  71.      *
  72.      * @param crc
  73.      *            checksum of all packed data (including object type code,
  74.      *            inflated length and delta base reference) as computed by
  75.      *            {@link java.util.zip.CRC32}.
  76.      */
  77.     public void setCRC(int crc) {
  78.         this.crc = crc;
  79.     }

  80.     /**
  81.      * Get the object type.
  82.      *
  83.      * @return the object type. The default type is OBJ_BAD, which is considered
  84.      *         as unknown or invalid type.
  85.      * @since 4.9
  86.      */
  87.     public int getType() {
  88.         return type;
  89.     }

  90.     /**
  91.      * Record the object type if applicable.
  92.      *
  93.      * @param type
  94.      *            the object type.
  95.      * @since 4.9
  96.      */
  97.     public void setType(int type) {
  98.         this.type = type;
  99.     }

  100.     /**
  101.      * Size in storage
  102.      *
  103.      * @param sizeBeforeInflating
  104.      */
  105.     void setSize(long sizeBeforeInflating) {
  106.         this.sizeBeforeInflating = sizeBeforeInflating;
  107.     }

  108.     /**
  109.      * Size in storage (maybe deflated and/or deltified).
  110.      *
  111.      * This is the size in storage. In packs, this is the bytes used by the
  112.      * object contents (themselves or as deltas) compressed by zlib (deflated).
  113.      *
  114.      * @return size in storage
  115.      */
  116.     long getSize() {
  117.         return sizeBeforeInflating;
  118.     }

  119.     /**
  120.      * Real (materialized) size of the object (inflated, undeltified)
  121.      *
  122.      * @param size
  123.      *            size of the object in bytes, without compressing nor
  124.      *            deltifying
  125.      * @since 6.4
  126.      */
  127.     public void setFullSize(long size) {
  128.         this.fullSize = size;
  129.     }

  130.     /**
  131.      * @return size of the object (inflated, undeltified)
  132.      *
  133.      * @since 6.4
  134.      */
  135.     public long getFullSize() {
  136.         return fullSize;
  137.     }
  138. }