Class AbstractRepository

java.lang.Object
ai.djl.repository.AbstractRepository
All Implemented Interfaces:
Repository
Direct Known Subclasses:
JarRepository, LocalRepository, RemoteRepository, SimpleRepository, SimpleUrlRepository

public abstract class AbstractRepository extends Object implements Repository
The AbstractRepository is the shared base for implementers of the Repository interface.
See Also:
  • Field Details

  • Constructor Details

    • AbstractRepository

      protected AbstractRepository(String name, URI uri)
  • Method Details

    • getName

      public String getName()
      Returns the repository name.
      Specified by:
      getName in interface Repository
      Returns:
      the repository name
    • getBaseUri

      public URI getBaseUri()
      Returns the URI to the base of the repository.
      Specified by:
      getBaseUri in interface Repository
      Returns:
      the URI
    • openStream

      public InputStream openStream(Artifact.Item item, String path) throws IOException
      Returns an InputStream for an item in a repository.
      Specified by:
      openStream in interface Repository
      Parameters:
      item - the item to open
      path - the path to a file if the item is a zipped directory. Otherwise, pass null
      Returns:
      the file stream
      Throws:
      IOException - if it failed to open the stream
    • listDirectory

      public String[] listDirectory(Artifact.Item item, String path) throws IOException
      Returns the list of files directly within a specified directory in a zipped directory item.
      Specified by:
      listDirectory in interface Repository
      Parameters:
      item - the zipped directory item
      path - the path within the zip directory
      Returns:
      the list of files/directories
      Throws:
      IOException - if it failed to list the directory
    • getFile

      public Path getFile(Artifact.Item item, String path) throws IOException
      Returns the path to a file for the item.
      Specified by:
      getFile in interface Repository
      Parameters:
      item - the item to find the path for
      path - the path to a file if the item is a zipped directory. Otherwise, pass null
      Returns:
      the file path
      Throws:
      IOException - if it failed to find the path
    • resolvePath

      protected URI resolvePath(Artifact.Item item, String path) throws IOException
      Throws:
      IOException
    • prepare

      public void prepare(Artifact artifact, ai.djl.util.Progress progress) throws IOException
      Prepares the artifact for use with progress tracking.
      Specified by:
      prepare in interface Repository
      Parameters:
      artifact - the artifact to prepare
      progress - the progress tracker
      Throws:
      IOException - if it failed to prepare
    • getCacheDirectory

      public Path getCacheDirectory() throws IOException
      Returns the cache directory for the repository.
      Specified by:
      getCacheDirectory in interface Repository
      Returns:
      the cache directory path
      Throws:
      IOException - if it failed to ensure the creation of the cache directory
    • addResource

      public void addResource(MRL mrl)
      Adds resource to the repository.
      Specified by:
      addResource in interface Repository
      Parameters:
      mrl - the resource to add
    • download

      protected void download(Path tmp, URI baseUri, Artifact.Item item, ai.djl.util.Progress progress) throws IOException
      Throws:
      IOException
    • save

      protected void save(InputStream is, Path tmp, Artifact.Item item, ai.djl.util.Progress progress) throws IOException
      Throws:
      IOException