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
IOException
public void consumeData(StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock) throws IOException
RepositoryStorage
consumeData
in interface RepositoryStorage
asset
- 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.IOException
public void consumeDataFromChannel(StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock) throws IOException
RepositoryStorage
consumeDataFromChannel
in interface RepositoryStorage
asset
- 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.IOException
public void writeData(StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock) throws IOException
RepositoryStorage
writeData
in interface RepositoryStorage
asset
- 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.IOException
public void writeDataToChannel(StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock) throws IOException
RepositoryStorage
writeDataToChannel
in interface RepositoryStorage
asset
- 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.IOException
public URI getLocation()
RepositoryStorage
getLocation
in interface RepositoryStorage
public void updateLocation(URI newLocation) throws IOException
updateLocation
in interface RepositoryStorage
newLocation
- The URI to the new locationIOException
- If the directory cannot be created.public StorageAsset getAsset(String path)
RepositoryStorage
getAsset
in interface RepositoryStorage
public StorageAsset addAsset(String path, boolean container)
RepositoryStorage
addAsset
in interface RepositoryStorage
path
- 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
RepositoryStorage
removeAsset
in interface RepositoryStorage
IOException
public StorageAsset moveAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException
RepositoryStorage
moveAsset
in interface RepositoryStorage
origin
- The original assetdestination
- The destination path pointing to the new asset.copyOptions
- The copy options.IOException
public void moveAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException
RepositoryStorage
moveAsset
in interface RepositoryStorage
origin
- The original assetdestination
- The destination path.copyOptions
- The copy options (e.g. StandardCopyOption.REPLACE_EXISTING
IOException
- If it was not possible to copy the asset.public StorageAsset copyAsset(StorageAsset origin, String destination, CopyOption... copyOptions) throws IOException
RepositoryStorage
copyAsset
in interface RepositoryStorage
origin
- The original assetdestination
- The path to the new assetcopyOptions
- The copy options, e.g. (e.g. StandardCopyOption.REPLACE_EXISTING
IOException
- If it was not possible to copy the assetpublic void copyAsset(StorageAsset origin, StorageAsset destination, CopyOption... copyOptions) throws IOException
RepositoryStorage
copyAsset
in interface RepositoryStorage
origin
- The original assetdestination
- The path to the new assetcopyOptions
- The copy options, e.g. (e.g. StandardCopyOption.REPLACE_EXISTING
IOException
- If it was not possible to copy the assetpublic FileLockManager getFileLockManager()
Copyright © 2006–2019 The Apache Software Foundation. All rights reserved.