public class FilesystemStorage extends Object implements RepositoryStorage
RepositoryStorage where data is stored in the filesystem.
All files are relative to a given base path. Path values are separated by '/', '..' is allowed to navigate
to a parent directory, but navigation out of the base path will lead to a exception.| Constructor and Description |
|---|
FilesystemStorage(Path basePath,
FileLockManager fileLockManager) |
| Modifier and Type | Method and Description |
|---|---|
StorageAsset |
addAsset(String path,
boolean container)
Adds a new asset to the underlying storage.
|
void |
consumeData(StorageAsset asset,
Consumer<InputStream> consumerFunction,
boolean readLock)
Consumes the data and sets a lock for the file during the operation.
|
void |
consumeDataFromChannel(StorageAsset asset,
Consumer<ReadableByteChannel> consumerFunction,
boolean readLock)
Consumes the data and sets a lock for the file during the operation.
|
void |
copyAsset(StorageAsset origin,
StorageAsset destination,
CopyOption... copyOptions)
Copies the given asset to the new destination.
|
StorageAsset |
copyAsset(StorageAsset origin,
String destination,
CopyOption... copyOptions)
Copies the given asset to the new destination.
|
StorageAsset |
getAsset(String path)
Returns information about a specific storage asset.
|
FileLockManager |
getFileLockManager() |
URI |
getLocation()
Returns a URI representation of the storage location.
|
void |
moveAsset(StorageAsset origin,
StorageAsset destination,
CopyOption... copyOptions)
Moves the asset to the given location and returns the asset object for the destination.
|
StorageAsset |
moveAsset(StorageAsset origin,
String destination,
CopyOption... copyOptions)
Moves the asset to the given location and returns the asset object for the destination.
|
void |
removeAsset(StorageAsset asset)
Removes the given asset from the storage.
|
void |
updateLocation(URI newLocation)
Updates the location and releases all locks.
|
void |
writeData(StorageAsset asset,
Consumer<OutputStream> consumerFunction,
boolean writeLock)
Writes data to the asset using a write lock.
|
void |
writeDataToChannel(StorageAsset asset,
Consumer<WritableByteChannel> consumerFunction,
boolean writeLock)
Writes data and sets a lock during the operation.
|
public FilesystemStorage(Path basePath, FileLockManager fileLockManager) throws IOException
IOExceptionpublic void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException
RepositoryStorageconsumeData in interface RepositoryStorageasset - The asset from which the data is consumed.consumerFunction - The consumer that reads the datareadLock - If true, a read lock is acquired on the asset.IOExceptionpublic void consumeDataFromChannel(StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException
RepositoryStorageconsumeDataFromChannel in interface RepositoryStorageasset - The asset from which the data is consumed.consumerFunction - The consumer that reads the datareadLock - If true, a read lock is acquired on the asset.IOExceptionpublic void writeData(StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock) throws IOException
RepositoryStoragewriteData in interface RepositoryStorageasset - The asset to which the data is written.consumerFunction - The function that provides the data.writeLock - If true, a write lock is acquired on the destination.IOExceptionpublic void writeDataToChannel(StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock) throws IOException
RepositoryStoragewriteDataToChannel in interface RepositoryStorageasset - The asset to which the data is written.consumerFunction - The function that provides the data.writeLock - If true, a write lock is acquired on the destination.IOExceptionpublic URI getLocation()
RepositoryStoragegetLocation in interface RepositoryStoragepublic void updateLocation(URI newLocation) throws IOException
updateLocation in interface RepositoryStoragenewLocation - The URI to the new locationIOException - If the directory cannot be created.public StorageAsset getAsset(String path)
RepositoryStoragegetAsset in interface RepositoryStoragepublic StorageAsset addAsset(String path, boolean container)
RepositoryStorageaddAsset in interface RepositoryStoragepath - The path to the asset.container - True, if the asset should be a container, false, if it is a file.public void removeAsset(StorageAsset asset) throws IOException
RepositoryStorageremoveAsset in interface RepositoryStorageIOExceptionpublic StorageAsset moveAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException
RepositoryStoragemoveAsset in interface RepositoryStorageorigin - The original assetdestination - The destination path pointing to the new asset.copyOptions - The copy options.IOExceptionpublic void moveAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException
RepositoryStoragemoveAsset in interface RepositoryStorageorigin - The original assetdestination - The destination path.copyOptions - The copy options (e.g. StandardCopyOption.REPLACE_EXISTINGIOException - If it was not possible to copy the asset.public StorageAsset copyAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException
RepositoryStoragecopyAsset in interface RepositoryStorageorigin - The original assetdestination - The path to the new assetcopyOptions - The copy options, e.g. (e.g. StandardCopyOption.REPLACE_EXISTINGIOException - If it was not possible to copy the assetpublic void copyAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException
RepositoryStoragecopyAsset in interface RepositoryStorageorigin - The original assetdestination - The path to the new assetcopyOptions - The copy options, e.g. (e.g. StandardCopyOption.REPLACE_EXISTINGIOException - If it was not possible to copy the assetpublic FileLockManager getFileLockManager()
Copyright © 2006–2019 The Apache Software Foundation. All rights reserved.