public abstract class AbstractRepository extends java.lang.Object implements Repository
AbstractRepository
is the shared base for implementers of the Repository
interface.Repository
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<java.lang.String,java.lang.String> |
arguments |
protected java.lang.String |
name |
protected java.net.URI |
uri |
Modifier | Constructor and Description |
---|---|
protected |
AbstractRepository(java.lang.String name,
java.net.URI uri) |
Modifier and Type | Method and 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.
|
protected static java.lang.String |
md5hash(java.lang.String input) |
java.io.InputStream |
openStream(Artifact.Item item,
java.lang.String path)
Returns an
InputStream 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) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
dataset, dataset, getResourceDirectory, getResources, isRemote, locate, model, model, model, newInstance, newInstance, prepare, registerRepositoryFactory, resolve
protected java.lang.String name
protected java.net.URI uri
protected java.util.Map<java.lang.String,java.lang.String> arguments
protected AbstractRepository(java.lang.String name, java.net.URI uri)
public java.lang.String getName()
getName
in interface Repository
public java.net.URI getBaseUri()
getBaseUri
in interface Repository
public java.io.InputStream openStream(Artifact.Item item, java.lang.String path) throws java.io.IOException
InputStream
for an item in a repository.openStream
in interface Repository
item
- the item to openpath
- the path to a file if the item is a zipped directory. Otherwise, pass nulljava.io.IOException
- if it failed to open the streampublic java.lang.String[] listDirectory(Artifact.Item item, java.lang.String path) throws java.io.IOException
listDirectory
in interface Repository
item
- the zipped directory itempath
- the path within the zip directoryjava.io.IOException
- if it failed to list the directorypublic java.nio.file.Path getFile(Artifact.Item item, java.lang.String path) throws java.io.IOException
getFile
in interface Repository
item
- the item to find the path forpath
- the path to a file if the item is a zipped directory. Otherwise, pass nulljava.io.IOException
- if it failed to find the pathprotected java.net.URI resolvePath(Artifact.Item item, java.lang.String path) throws java.io.IOException
java.io.IOException
public void prepare(Artifact artifact, ai.djl.util.Progress progress) throws java.io.IOException
prepare
in interface Repository
artifact
- the artifact to prepareprogress
- the progress trackerjava.io.IOException
- if it failed to preparepublic java.nio.file.Path getCacheDirectory() throws java.io.IOException
getCacheDirectory
in interface Repository
java.io.IOException
- if it failed to ensure the creation of the cache directorypublic void addResource(MRL mrl)
addResource
in interface Repository
mrl
- the resource to addprotected void download(java.nio.file.Path tmp, java.net.URI baseUri, Artifact.Item item, ai.djl.util.Progress progress) throws java.io.IOException
java.io.IOException
protected void save(java.io.InputStream is, java.nio.file.Path tmp, Artifact.Item item, ai.djl.util.Progress progress) throws java.io.IOException
java.io.IOException
protected static java.lang.String md5hash(java.lang.String input)