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.     PackedObjectInfo(final long headerOffset, final int packedCRC,
  28.             final AnyObjectId id) {
  29.         super(id);
  30.         offset = headerOffset;
  31.         crc = packedCRC;
  32.     }

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

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

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

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

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

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

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

  99.     void setSize(long sizeBeforeInflating) {
  100.         this.sizeBeforeInflating = sizeBeforeInflating;
  101.     }

  102.     long getSize() {
  103.         return sizeBeforeInflating;
  104.     }
  105. }