public abstract class AbstractRepository extends java.lang.Object implements Repository
AbstractRepository
is the shared base for implementers of the Repository
interface.Repository
GSON
Constructor and Description |
---|
AbstractRepository() |
Modifier and Type | Method and Description |
---|---|
protected void |
download(java.nio.file.Path tmp,
java.net.URI baseUri,
Artifact.Item item,
ai.djl.util.Progress progress) |
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.util.List<MRL> |
getResources()
Returns a list of
MRL s in the repository. |
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,
java.net.URI baseUri,
Artifact.Item item,
ai.djl.util.Progress progress) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBaseUri, getName, getResourceDirectory, isRemote, locate, newInstance, newInstance, prepare, registerRepositoryFactory, resolve
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 java.util.List<MRL> getResources()
MRL
s in the repository.
An empty list will be returned if underlying Repository
implementation does not
support this feature.
getResources
in interface Repository
MRL
s in the repositoryprotected 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, java.net.URI baseUri, 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)