public class FilesystemAsset extends Object implements StorageAsset, Comparable
The implementation does not check the given paths. Caller should normalize the asset path and check, if the base path is a parent of the resulting path.
The file must not exist for all operations.
Modifier and Type | Field and Description |
---|---|
static AclEntryPermission[] |
DEFAULT_ACL_DIR_PERMISSIONS |
static AclEntryPermission[] |
DEFAULT_ACL_FILE_PERMISSIONS |
static Set<PosixFilePermission> |
DEFAULT_POSIX_DIR_PERMISSIONS |
static String |
DEFAULT_POSIX_DIR_PERMS |
static Set<PosixFilePermission> |
DEFAULT_POSIX_FILE_PERMISSIONS |
static String |
DEFAULT_POSIX_FILE_PERMS |
Constructor and Description |
---|
FilesystemAsset(RepositoryStorage storage,
String path,
Path assetPath)
Creates an asset for the given path.
|
FilesystemAsset(RepositoryStorage storage,
String path,
Path assetPath,
Path basePath,
boolean directory)
Creates an asset for the given path.
|
FilesystemAsset(RepositoryStorage storage,
String path,
Path assetPath,
Path basePath,
boolean directory,
boolean setPermissionsForNew)
Creates an asset for the given path.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Object o) |
void |
create()
Creates the asset in the underlying storage, if it does not exist.
|
boolean |
exists()
Returns true, if the asset exists.
|
List<AclEntry> |
getDefaultDirectoryAcls() |
List<AclEntry> |
getDefaultFileAcls() |
Set<PosixFilePermission> |
getDefaultPosixDirectoryPermissions() |
Set<PosixFilePermission> |
getDefaultPosixFilePermissions() |
Path |
getFilePath()
Returns the real path to the asset, if it exist.
|
Instant |
getModificationTime()
Returns the time of the last modification.
|
String |
getName()
Returns the name of the asset.
|
StorageAsset |
getParent()
Returns the parent of this asset.
|
String |
getPath()
Returns the complete path relative to the repository to the given asset.
|
ReadableByteChannel |
getReadChannel()
Returns a NIO representation of the data.
|
InputStream |
getReadStream()
Returns a input stream to the underlying file, if it exists.
|
long |
getSize()
Returns the size of the represented file.
|
RepositoryStorage |
getStorage()
Returns the storage this asset belongs to.
|
WritableByteChannel |
getWriteChannel(boolean replace)
Returns a NIO representation of the asset where you can write the data.
|
OutputStream |
getWriteStream(boolean replace)
Returns an output stream where you can write data to the asset.
|
boolean |
hasParent()
Returns true, if there is a parent to this asset.
|
boolean |
isContainer()
Returns true, if the path of this asset points to a directory
|
boolean |
isFileBased()
Returns true, if the asset can return a file path for the given asset.
|
List<StorageAsset> |
list()
Returns the list of directory entries, if this asset represents a directory.
|
boolean |
replaceDataFromFile(Path newData)
Replaces the content.
|
StorageAsset |
resolve(String toPath)
Returns the asset relative to the given path
|
void |
setDefaultDirectoryAcls(List<AclEntry> acl) |
void |
setDefaultFileAcls(List<AclEntry> acl) |
void |
setDefaultPosixDirectoryPermissions(Set<PosixFilePermission> perms) |
void |
setDefaultPosixFilePermissions(Set<PosixFilePermission> perms) |
String |
toString() |
public static final String DEFAULT_POSIX_FILE_PERMS
public static final String DEFAULT_POSIX_DIR_PERMS
public static final Set<PosixFilePermission> DEFAULT_POSIX_FILE_PERMISSIONS
public static final Set<PosixFilePermission> DEFAULT_POSIX_DIR_PERMISSIONS
public static final AclEntryPermission[] DEFAULT_ACL_FILE_PERMISSIONS
public static final AclEntryPermission[] DEFAULT_ACL_DIR_PERMISSIONS
public FilesystemAsset(RepositoryStorage storage, String path, Path assetPath)
path
- The logical path for the asset relative to the repository.assetPath
- The asset path.public FilesystemAsset(RepositoryStorage storage, String path, Path assetPath, Path basePath, boolean directory)
path
- The logical path for the asset relative to the repositoryassetPath
- The asset path.directory
- This is only relevant, if the represented file or directory does not exist yet and
is a hint.public FilesystemAsset(RepositoryStorage storage, String path, Path assetPath, Path basePath, boolean directory, boolean setPermissionsForNew)
path
- The logical path for the asset relative to the repositoryassetPath
- The asset path.directory
- This is only relevant, if the represented file or directory does not exist yet and
is a hint.public RepositoryStorage getStorage()
StorageAsset
getStorage
in interface StorageAsset
public String getPath()
StorageAsset
getPath
in interface StorageAsset
public String getName()
StorageAsset
getName
in interface StorageAsset
public Instant getModificationTime()
StorageAsset
getModificationTime
in interface StorageAsset
public boolean isContainer()
isContainer
in interface StorageAsset
public List<StorageAsset> list()
list
in interface StorageAsset
public long getSize()
getSize
in interface StorageAsset
public InputStream getReadStream() throws IOException
getReadStream
in interface StorageAsset
IOException
public ReadableByteChannel getReadChannel() throws IOException
StorageAsset
getReadChannel
in interface StorageAsset
IOException
public OutputStream getWriteStream(boolean replace) throws IOException
StorageAsset
getWriteStream
in interface StorageAsset
replace
- If true, the original data will be replaced, otherwise the data will be appended.IOException
public WritableByteChannel getWriteChannel(boolean replace) throws IOException
StorageAsset
getWriteChannel
in interface StorageAsset
replace
- True, if the content should be replaced by the data written to the stream.IOException
public boolean replaceDataFromFile(Path newData) throws IOException
StorageAsset
replaceDataFromFile
in interface StorageAsset
newData
- Replaces the data by the content of the given file.IOException
public boolean exists()
StorageAsset
exists
in interface StorageAsset
public Path getFilePath() throws UnsupportedOperationException
StorageAsset
UnsupportedOperationException
, if and only if StorageAsset.isFileBased()
returns false.getFilePath
in interface StorageAsset
UnsupportedOperationException
- If the underlying storage is not file based.public boolean isFileBased()
StorageAsset
StorageAsset.getFilePath()
will not throw a UnsupportedOperationException
isFileBased
in interface StorageAsset
public boolean hasParent()
StorageAsset
hasParent
in interface StorageAsset
public StorageAsset getParent()
StorageAsset
getParent
in interface StorageAsset
null
, if it does not exist.public StorageAsset resolve(String toPath)
StorageAsset
resolve
in interface StorageAsset
public void setDefaultFileAcls(List<AclEntry> acl)
public List<AclEntry> getDefaultFileAcls()
public void setDefaultPosixFilePermissions(Set<PosixFilePermission> perms)
public Set<PosixFilePermission> getDefaultPosixFilePermissions()
public void setDefaultDirectoryAcls(List<AclEntry> acl)
public List<AclEntry> getDefaultDirectoryAcls()
public void setDefaultPosixDirectoryPermissions(Set<PosixFilePermission> perms)
public Set<PosixFilePermission> getDefaultPosixDirectoryPermissions()
public void create() throws IOException
StorageAsset
create
in interface StorageAsset
IOException
public int compareTo(Object o)
compareTo
in interface Comparable
Copyright © 2006–2019 The Apache Software Foundation. All rights reserved.