Package ai.djl.repository
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 java.lang.Object implements Repository
TheAbstractRepositoryis the shared base for implementers of theRepositoryinterface.- See Also:
Repository
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractRepository(java.lang.String name, java.net.URI uri)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddResource(MRL mrl)Adds resource to the repository.protected voiddownload(java.nio.file.Path tmp, java.net.URI baseUri, Artifact.Item item, ai.djl.util.Progress progress)java.net.URIgetBaseUri()Returns the URI to the base of the repository.java.nio.file.PathgetCacheDirectory()Returns the cache directory for the repository.java.nio.file.PathgetFile(Artifact.Item item, java.lang.String path)Returns the path to a file for the item.java.lang.StringgetName()Returns the repository name.java.lang.String[]listDirectory(Artifact.Item item, java.lang.String path)Returns the list of files directly within a specified directory in a zipped directory item.java.io.InputStreamopenStream(Artifact.Item item, java.lang.String path)Returns anInputStreamfor an item in a repository.voidprepare(Artifact artifact, ai.djl.util.Progress progress)Prepares the artifact for use with progress tracking.protected java.net.URIresolvePath(Artifact.Item item, java.lang.String path)protected voidsave(java.io.InputStream is, java.nio.file.Path tmp, Artifact.Item item, ai.djl.util.Progress progress)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ai.djl.repository.Repository
dataset, dataset, getResourceDirectory, getResources, isRemote, locate, model, model, model, prepare, resolve
-
-
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the repository name.- Specified by:
getNamein interfaceRepository- Returns:
- the repository name
-
getBaseUri
public java.net.URI getBaseUri()
Returns the URI to the base of the repository.- Specified by:
getBaseUriin interfaceRepository- Returns:
- the URI
-
openStream
public java.io.InputStream openStream(Artifact.Item item, java.lang.String path) throws java.io.IOException
Returns anInputStreamfor an item in a repository.- Specified by:
openStreamin interfaceRepository- Parameters:
item- the item to openpath- the path to a file if the item is a zipped directory. Otherwise, pass null- Returns:
- the file stream
- Throws:
java.io.IOException- if it failed to open the stream
-
listDirectory
public java.lang.String[] listDirectory(Artifact.Item item, java.lang.String path) throws java.io.IOException
Returns the list of files directly within a specified directory in a zipped directory item.- Specified by:
listDirectoryin interfaceRepository- Parameters:
item- the zipped directory itempath- the path within the zip directory- Returns:
- the list of files/directories
- Throws:
java.io.IOException- if it failed to list the directory
-
getFile
public java.nio.file.Path getFile(Artifact.Item item, java.lang.String path) throws java.io.IOException
Returns the path to a file for the item.- Specified by:
getFilein interfaceRepository- Parameters:
item- the item to find the path forpath- the path to a file if the item is a zipped directory. Otherwise, pass null- Returns:
- the file path
- Throws:
java.io.IOException- if it failed to find the path
-
resolvePath
protected java.net.URI resolvePath(Artifact.Item item, java.lang.String path) throws java.io.IOException
- Throws:
java.io.IOException
-
prepare
public void prepare(Artifact artifact, ai.djl.util.Progress progress) throws java.io.IOException
Prepares the artifact for use with progress tracking.- Specified by:
preparein interfaceRepository- Parameters:
artifact- the artifact to prepareprogress- the progress tracker- Throws:
java.io.IOException- if it failed to prepare
-
getCacheDirectory
public java.nio.file.Path getCacheDirectory() throws java.io.IOExceptionReturns the cache directory for the repository.- Specified by:
getCacheDirectoryin interfaceRepository- Returns:
- the cache directory path
- Throws:
java.io.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:
addResourcein interfaceRepository- Parameters:
mrl- the resource to add
-
download
protected void download(java.nio.file.Path tmp, java.net.URI baseUri, Artifact.Item item, ai.djl.util.Progress progress) throws java.io.IOException- Throws:
java.io.IOException
-
save
protected void save(java.io.InputStream is, java.nio.file.Path tmp, Artifact.Item item, ai.djl.util.Progress progress) throws java.io.IOException- Throws:
java.io.IOException
-
-