1 /* 2 * Copyright (C) 2019, Google LLC. 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.pack; 11 12 import java.io.IOException; 13 import java.util.Collection; 14 import org.eclipse.jgit.annotations.Nullable; 15 16 /** 17 * Provider of URIs corresponding to cached packs. For use with the 18 * "packfile-uris" feature. 19 * @since 5.5 20 */ 21 public interface CachedPackUriProvider { 22 23 /** 24 * @param pack the cached pack for which to check if a corresponding URI 25 * exists 26 * @param protocolsSupported the protocols that the client has declared 27 * support for; if a URI is returned, it must be of one of these 28 * protocols 29 * @throws IOException implementations may throw this 30 * @return if a URI corresponds to the cached pack, an object 31 * containing the URI and some other information; null otherwise 32 * @since 5.5 33 */ 34 @Nullable 35 PackInfo getInfo(CachedPack pack, Collection<String> protocolsSupported) 36 throws IOException; 37 38 /** 39 * Information about a packfile. 40 * @since 5.5 41 */ 42 public static class PackInfo { 43 private final String hash; 44 private final String uri; 45 46 private final long size; 47 48 /** 49 * Constructs an object containing information about a packfile. 50 * 51 * @param hash 52 * the hash of the packfile as a hexadecimal string 53 * @param uri 54 * the URI corresponding to the packfile 55 * @param size 56 * the size of the packfile in bytes 57 */ 58 public PackInfo(String hash, String uri, long size) { 59 this.hash = hash; 60 this.uri = uri; 61 this.size = size; 62 } 63 64 /** 65 * @return the hash of the packfile as a hexadecimal string 66 */ 67 public String getHash() { 68 return hash; 69 } 70 71 /** 72 * @return the URI corresponding to the packfile 73 */ 74 public String getUri() { 75 return uri; 76 } 77 78 /** 79 * @return the size of the packfile in bytes (-1 if unknown) 80 */ 81 public long getSize() { 82 return size; 83 } 84 } 85 }