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
TheAbstractRepository
is the shared base for implementers of theRepository
interface.- See Also:
Repository
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractRepository(java.lang.String name, java.net.URI uri)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addResource(MRL mrl)
Adds resource to the repository.protected void
download(java.nio.file.Path tmp, java.net.URI baseUri, Artifact.Item item, ai.djl.util.Progress progress)
java.net.URI
getBaseUri()
Returns the URI to the base of the repository.java.nio.file.Path
getCacheDirectory()
Returns the cache directory for the repository.java.nio.file.Path
getFile(Artifact.Item item, java.lang.String path)
Returns the path to a file for the item.java.lang.String
getName()
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.InputStream
openStream(Artifact.Item item, java.lang.String path)
Returns anInputStream
for an item in a repository.void
prepare(Artifact artifact, ai.djl.util.Progress progress)
Prepares the artifact for use with progress tracking.protected java.net.URI
resolvePath(Artifact.Item item, java.lang.String path)
protected void
save(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:
getName
in interfaceRepository
- Returns:
- the repository name
-
getBaseUri
public java.net.URI getBaseUri()
Returns the URI to the base of the repository.- Specified by:
getBaseUri
in interfaceRepository
- Returns:
- the URI
-
openStream
public java.io.InputStream openStream(Artifact.Item item, java.lang.String path) throws java.io.IOException
Returns anInputStream
for an item in a repository.- Specified by:
openStream
in 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:
listDirectory
in 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:
getFile
in 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:
prepare
in 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.IOException
Returns the cache directory for the repository.- Specified by:
getCacheDirectory
in 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:
addResource
in 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
-
-