Interface Workspace
- All Superinterfaces:
StorageUsage
- All Known Implementing Classes:
WorkspaceImpl
Provides efficient access java.io.File objects from potentially remote URIs. This helper service prevents different
service implementations running in the same osgi container from downloading remote files multiple times.
Additionally, when the system is configured to use shared storage, this performance gain is also achieved across
distributed osgi containers. The methods from WorkingFileRepository are also available as a convenience to clients.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup(int maxAge) Cleans up files not belonging to a mediapackage or a collection.voidClean up all elements of one media package from the local workspace, not touching the working file repository.voidClean up elements of one media package from the local workspace, not touching the working file repository.voidDelete the file stored at the given media package and element IDs.voidDelete the file stored at the given uri.voiddeleteFromCollection(String collectionId, String fileName) Removes a file from a collectionGets a locally cachedFilefor the given URI.Get a locally cachedFilefor a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.Gets the base URI for files stored using this service.URI[]getCollectionContents(String collectionId) Gets the URIs of the members of this collectiongetCollectionURI(String collectionID, String fileName) Get the URL for a file stored under the given collection.Get the URL for a file stored under the given media package and element IDs.Moves a file from a collection into a mediapackageput(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) Store the data stream under the given media package and element IDs, specifying a filename.putInCollection(String collectionId, String fileName, InputStream in) Stores the data stream in the given collection, overwriting any data with the same collection id and file name.Get theFilefor the given URI directly from the working file repository.Returns the workspace's root directorytoSafeName(String fileName) Methods inherited from interface org.opencastproject.storage.StorageUsage
getTotalSpace, getUsableSpace, getUsedSpace
-
Method Details
-
toSafeName
-
get
Gets a locally cachedFilefor the given URI.- Parameters:
uri-- Returns:
- The locally cached file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
get
Get a locally cachedFilefor a given URI, optionally ensuring that the file is cached in a unique path so that it can safely be removed afterwards.- Parameters:
uri- URI to the resource to getuniqueFilename- If a unique path should be used- Returns:
- The locally cached file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the workspace fails
-
read
Get theFilefor the given URI directly from the working file repository. If shared storage is not available, then fall back to get(uri).- Parameters:
uri- URI identifying the resource to load- Returns:
- The file
- Throws:
NotFoundException- if the file does not existIOException- if reading the file from the working file repository fails
-
getBaseUri
URI getBaseUri()Gets the base URI for files stored using this service.- Returns:
- The base URI
-
put
URI put(String mediaPackageID, String mediaPackageElementID, String fileName, InputStream in) throws IOException, IllegalArgumentException Store the data stream under the given media package and element IDs, specifying a filename.- Parameters:
mediaPackageID-mediaPackageElementID-fileName-in-- Throws:
IOException- if writing the data to the workspace failsIllegalArgumentException- if a URI cannot be created using the arguments provided
-
putInCollection
URI putInCollection(String collectionId, String fileName, InputStream in) throws IOException, IllegalArgumentException Stores the data stream in the given collection, overwriting any data with the same collection id and file name.- Parameters:
collectionId- The collection to use for storing this datafileName- the filename to use in the collection.in- the inputstream- Returns:
- the URI of the stored data
- Throws:
IOException- if writing the data to the workspace failsIllegalArgumentException- if a URI cannot be created using the arguments provided
-
getCollectionContents
Gets the URIs of the members of this collection- Parameters:
collectionId- the collection identifier- Returns:
- the URIs for each member of the collection
- Throws:
NotFoundException- if the collection cannot be foundIllegalArgumentException- if a URI cannot be created using the arguments provided
-
delete
Delete the file stored at the given uri.- Parameters:
uri- the uri- Throws:
NotFoundException- if there was not file stored under this combination of mediapackage and element IDs.IOException- if deleting the data from the workspace fails
-
delete
void delete(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException Delete the file stored at the given media package and element IDs.- Parameters:
mediaPackageID-mediaPackageElementID-- Throws:
NotFoundException- if there was not file stored under this combination of mediapackage and element IDs.IOException- if deleting the data from the workspace fails
-
deleteFromCollection
void deleteFromCollection(String collectionId, String fileName) throws NotFoundException, IOException Removes a file from a collection- Parameters:
collectionId- the collection identifierfileName- the filename to remove- Throws:
NotFoundException- if there was no file with the provided name stored under this collection.IOException- if deleting the data from the workspace fails
-
getURI
Get the URL for a file stored under the given media package and element IDs. MediaPackages may reference elements that are not yet stored in the working file repository, so this method will return a URI even if the file is not yet stored.- Parameters:
mediaPackageID- the mediapackage identifiermediaPackageElementID- the element identifier- Returns:
- the URI to the file
- Throws:
IllegalArgumentException- if a URI cannot be created using the arguments provided
-
getCollectionURI
Get the URL for a file stored under the given collection.- Parameters:
collectionID- the collection idfileName- the file name- Returns:
- the file's uri
- Throws:
IllegalArgumentException- if a URI cannot be created using the arguments provided
-
moveTo
URI moveTo(URI collectionURI, String toMediaPackage, String toMediaPackageElement, String toFileName) throws NotFoundException, IOException, IllegalArgumentException Moves a file from a collection into a mediapackage- Parameters:
collectionURI- the uri pointing to a workspace collectiontoMediaPackage- The media package ID to move the file intotoMediaPackageElement- the media package element ID of the filetoFileName- the name of the resulting file- Returns:
- the URI pointing to the file's new location
- Throws:
NotFoundException- if the element identified bycollectionURIcannot be foundIOException- if either the original element cannot be read or it cannot be moved to the new locationIllegalArgumentException- if a URI cannot be created using the arguments provided
-
cleanup
void cleanup(int maxAge) Cleans up files not belonging to a mediapackage or a collection. If the optional maxAge parameter is set, only files older than the maxAge are deleted.- Parameters:
maxAge- the maximal age in seconds of a file before deletion is performed
-
cleanup
Clean up all elements of one media package from the local workspace, not touching the working file repository.- Parameters:
mediaPackageId- Id specifying the media package to remove files for.- Throws:
IOException
-
cleanup
Clean up elements of one media package from the local workspace, not touching the working file repository.- Parameters:
mediaPackageId- Id specifying the media package to remove files for.filesOnly- Boolean specifying whether only files or also directories (including the root directory) are deleted.- Throws:
IOException
-
rootDirectory
String rootDirectory()Returns the workspace's root directory- Returns:
- Path to the workspace root directory
-