|
20 | 20 |
|
21 | 21 | package land.oras;
|
22 | 22 |
|
| 23 | +import java.io.InputStream; |
| 24 | +import java.nio.file.Path; |
| 25 | +import org.jspecify.annotations.Nullable; |
| 26 | + |
23 | 27 | /**
|
24 | 28 | * Abstract class for OCI operation on remote registry or layout
|
| 29 | + * Commons methods for OCI operations |
| 30 | + * @param <T> The reference type |
25 | 31 | */
|
26 |
| -public abstract sealed class OCI permits Registry, OCILayout { |
| 32 | +public abstract sealed class OCI<T extends Ref> permits Registry, OCILayout { |
27 | 33 |
|
28 | 34 | /**
|
29 | 35 | * Default constructor
|
30 | 36 | */
|
31 |
| - public OCI() {} |
| 37 | + protected OCI() {} |
| 38 | + |
| 39 | + /** |
| 40 | + * Push an artifact |
| 41 | + * @param ref The ref |
| 42 | + * @param paths The paths |
| 43 | + * @return The manifest |
| 44 | + */ |
| 45 | + public Manifest pushArtifact(T ref, LocalPath... paths) { |
| 46 | + return pushArtifact(ref, ArtifactType.unknown(), Annotations.empty(), Config.empty(), paths); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Push an artifact |
| 51 | + * @param ref The ref |
| 52 | + * @param artifactType The artifact type |
| 53 | + * @param paths The paths |
| 54 | + * @return The manifest |
| 55 | + */ |
| 56 | + public Manifest pushArtifact(T ref, ArtifactType artifactType, LocalPath... paths) { |
| 57 | + return pushArtifact(ref, artifactType, Annotations.empty(), Config.empty(), paths); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Upload an ORAS artifact |
| 62 | + * @param ref The ref |
| 63 | + * @param artifactType The artifact type |
| 64 | + * @param annotations The annotations |
| 65 | + * @param paths The paths |
| 66 | + * @return The manifest |
| 67 | + */ |
| 68 | + public Manifest pushArtifact(T ref, ArtifactType artifactType, Annotations annotations, LocalPath... paths) { |
| 69 | + return pushArtifact(ref, artifactType, annotations, Config.empty(), paths); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Push an artifact |
| 74 | + * @param ref The container |
| 75 | + * @param artifactType The artifact type. Can be null |
| 76 | + * @param annotations The annotations |
| 77 | + * @param config The config |
| 78 | + * @param paths The paths |
| 79 | + * @return The manifest |
| 80 | + */ |
| 81 | + public abstract Manifest pushArtifact( |
| 82 | + T ref, ArtifactType artifactType, Annotations annotations, @Nullable Config config, LocalPath... paths); |
| 83 | + |
| 84 | + /** |
| 85 | + * Pull an artifact |
| 86 | + * @param ref The reference of the artifact |
| 87 | + * @param path The path to save the artifact |
| 88 | + * @param overwrite Overwrite the artifact if it exists |
| 89 | + */ |
| 90 | + public abstract void pullArtifact(T ref, Path path, boolean overwrite); |
| 91 | + |
| 92 | + /** |
| 93 | + * Get the blob for the given digest. Not be suitable for large blobs |
| 94 | + * @param ref The ref |
| 95 | + * @return The blob as bytes |
| 96 | + */ |
| 97 | + public abstract byte[] getBlob(T ref); |
| 98 | + |
| 99 | + /** |
| 100 | + * Fetch blob and save it to file |
| 101 | + * @param ref The ref |
| 102 | + * @param path The path to save the blob |
| 103 | + */ |
| 104 | + public abstract void fetchBlob(T ref, Path path); |
| 105 | + |
| 106 | + /** |
| 107 | + * Fetch blob and return it as input stream |
| 108 | + * @param ref The ref |
| 109 | + * @return The input stream |
| 110 | + */ |
| 111 | + public abstract InputStream fetchBlob(T ref); |
32 | 112 | }
|
0 commit comments