DfsCachedPack.java

  1. /*
  2.  * Copyright (C) 2011, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.internal.storage.dfs;

  11. import java.io.IOException;

  12. import org.eclipse.jgit.internal.storage.pack.CachedPack;
  13. import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
  14. import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
  15. import org.eclipse.jgit.internal.storage.pack.StoredObjectRepresentation;

  16. /**
  17.  * A DfsPackFile available for reuse as-is.
  18.  */
  19. public class DfsCachedPack extends CachedPack {
  20.     private final DfsPackFile pack;

  21.     DfsCachedPack(DfsPackFile pack) {
  22.         this.pack = pack;
  23.     }

  24.     /**
  25.      * @return the pack passed to the constructor
  26.      */
  27.     public DfsPackFile getPackFile() {
  28.         return pack;
  29.     }

  30.     /**
  31.      * Get the description of the pack.
  32.      *
  33.      * @return the description of the pack.
  34.      */
  35.     public DfsPackDescription getPackDescription() {
  36.         return pack.getPackDescription();
  37.     }

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     public long getObjectCount() throws IOException {
  41.         return getPackDescription().getObjectCount();
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public long getDeltaCount() throws IOException {
  46.         return getPackDescription().getDeltaCount();
  47.     }

  48.     /** {@inheritDoc} */
  49.     @Override
  50.     public boolean hasObject(ObjectToPack obj, StoredObjectRepresentation rep) {
  51.         return ((DfsObjectRepresentation) rep).pack == pack;
  52.     }

  53.     void copyAsIs(PackOutputStream out, DfsReader ctx) throws IOException {
  54.         pack.copyPackAsIs(out, ctx);
  55.     }
  56. }