View Javadoc
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  
11  package org.eclipse.jgit.internal.storage.dfs;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.internal.storage.pack.CachedPack;
16  import org.eclipse.jgit.internal.storage.pack.ObjectToPack;
17  import org.eclipse.jgit.internal.storage.pack.PackOutputStream;
18  import org.eclipse.jgit.internal.storage.pack.StoredObjectRepresentation;
19  
20  /**
21   * A DfsPackFile available for reuse as-is.
22   */
23  public class DfsCachedPack extends CachedPack {
24  	private final DfsPackFile pack;
25  
26  	DfsCachedPack(DfsPackFile pack) {
27  		this.pack = pack;
28  	}
29  
30  	/**
31  	 * @return the pack passed to the constructor
32  	 */
33  	public DfsPackFile getPackFile() {
34  		return pack;
35  	}
36  
37  	/**
38  	 * Get the description of the pack.
39  	 *
40  	 * @return the description of the pack.
41  	 */
42  	public DfsPackDescription getPackDescription() {
43  		return pack.getPackDescription();
44  	}
45  
46  	/** {@inheritDoc} */
47  	@Override
48  	public long getObjectCount() throws IOException {
49  		return getPackDescription().getObjectCount();
50  	}
51  
52  	/** {@inheritDoc} */
53  	@Override
54  	public long getDeltaCount() throws IOException {
55  		return getPackDescription().getDeltaCount();
56  	}
57  
58  	/** {@inheritDoc} */
59  	@Override
60  	public boolean hasObject(ObjectToPack obj, StoredObjectRepresentation rep) {
61  		return ((DfsObjectRepresentation) rep).pack == pack;
62  	}
63  
64  	void copyAsIs(PackOutputStream out, DfsReader ctx) throws IOException {
65  		pack.copyPackAsIs(out, ctx);
66  	}
67  }