public class CheckedPath
extends java.lang.Object
CheckedPath objects store various interpretations of paths that
are passed in by users. One of these objects should be created at the
very beginning of any PublicRepositoryI remote method (i.e. those
public methods which take Current instance arguments. Methods
are then available to check various capabilities by the current user. When
a null CheckedPath object is passed into the constructor the caller
indicates that the path is the root path, hence isRoot
will not be called.| Modifier and Type | Field and Description |
|---|---|
FsFile |
fsFile |
protected java.lang.String |
hash |
protected java.lang.Long |
id |
boolean |
isRoot |
protected java.lang.String |
mime |
| Constructor and Description |
|---|
CheckedPath(ServerFilePathTransformer serverPaths,
java.lang.String path,
ome.util.checksum.ChecksumProviderFactory checksumProviderFactory,
ChecksumAlgorithm checksumAlgorithm)
Construct a CheckedPath from a relative "/"-delimited path rooted at the repository.
|
| Modifier and Type | Method and Description |
|---|---|
ome.model.core.OriginalFile |
asOriginalFile(java.lang.String mimetype)
Creates an
OriginalFile instance for the given
CheckedPath even if it doesn't exist. |
void |
bfSetId(loci.formats.ReaderWrapper reader)
Perform BioFormats
ReaderWrapper.setId(String) for this file. |
boolean |
canEdit() |
boolean |
canRead()
Check if this file is actually readable on the underlying filesystem.
|
CheckedPath |
child(java.lang.String name)
Returns a new
CheckedPath that has the given path appended
to the end of this instances path. |
boolean |
equals(java.lang.Object object)
Instances are equal if their string representations match.
|
boolean |
exists()
Check if this file actually exists on the underlying filesystem.
|
protected java.lang.String |
getDirname()
Assuming this is a directory, return relative path plus name with a final
slash.
|
ome.io.nio.FileBuffer |
getFileBuffer(java.lang.String mode)
Get a
FileBuffer corresponding to this instance. |
protected java.lang.String |
getFullFsPath()
The full path of the entity to which this path corresponds.
|
java.lang.Long |
getId() |
java.lang.String |
getMimetype()
Get the mimetype for a file.
|
protected java.lang.String |
getName()
Get the last component of this path, the entity to which the path corresponds.
|
protected java.lang.String |
getRelativePath()
Get the parent path of the entity to which this path corresponds.
|
java.lang.String |
hash() |
int |
hashCode()
On Windows systems the calculation is not case-sensitive.
|
boolean |
isDirectory() |
boolean |
markModified()
Mark this existing file as having been modified at the present moment.
|
boolean |
mkdir()
Create this directory on the underlying filesystem.
|
boolean |
mkdirs()
Create this directory, and parents if necessary, on the underlying filesystem.
|
CheckedPath |
mustEdit() |
CheckedPath |
mustExist()
Checks for existence of the original path, throwing an exception if
not present.
|
CheckedPath |
parent()
Returns a new
CheckedPath using File.getParent() and
passing in all other values. |
void |
setId(java.lang.Long id) |
boolean |
setReadOnly()
Mark the underlying
File as read-only and return true
if the operation was successful. |
long |
size()
Return the size of this file on the underlying filesystem.
|
java.lang.String |
toString() |
public final FsFile fsFile
public boolean isRoot
protected java.lang.Long id
protected java.lang.String hash
protected java.lang.String mime
public CheckedPath(ServerFilePathTransformer serverPaths, java.lang.String path, ome.util.checksum.ChecksumProviderFactory checksumProviderFactory, ChecksumAlgorithm checksumAlgorithm) throws ValidationException
.and
..are understood to have their usual meaning. An empty path is the repository root.
serverPaths - the server path handling servicepath - a repository pathchecksumProviderFactory - a source of checksum providers,
may be null if checksumAlgorithm is also nullchecksumAlgorithm - the algorithm to use in hash()'s calculationsValidationException - if the path is empty or contains illegal componentspublic java.lang.Long getId()
public void setId(java.lang.Long id)
public java.lang.String hash()
public java.lang.String getMimetype()
public CheckedPath parent() throws ValidationException
CheckedPath using File.getParent() and
passing in all other values. Just as if calling the constructor,
bad paths will cause a ValidationException to be thrown.
CheckedPaths generated with this method always return a
null hash.ValidationExceptionpublic CheckedPath child(java.lang.String name) throws ValidationException
CheckedPath that has the given path appended
to the end of this instances path. A check is made that the name does
not contain "/" (i.e. subpaths) nor that it is ".." or ".".
CheckedPaths generated with this method always return a
null hash.name - ValidationExceptionpublic boolean exists()
File.exists().true if the file exists, false otherwisepublic CheckedPath mustExist() throws ValidationException
ValidationExceptionpublic CheckedPath mustEdit() throws SecurityViolation
SecurityViolationpublic boolean canRead()
File.canRead().true if the file is readable, false otherwisepublic boolean canEdit()
public boolean isDirectory()
protected java.lang.String getDirname()
protected java.lang.String getName()
isRoot then this is the empty string.protected java.lang.String getRelativePath()
FsFile.separatorChar.FsFile.separatorChar.protected java.lang.String getFullFsPath()
FsFile.separatorChar.public ome.io.nio.FileBuffer getFileBuffer(java.lang.String mode)
FileBuffer corresponding to this instance.
It is the caller's responsibility to FileBuffer.close() it.mode - as for RandomAccessFile(File, String),
"r" and "rw" being common choicesFileBufferpublic long size()
File.length().public boolean mkdir()
File.mkdir().true if the directory was created, false otherwisepublic boolean setReadOnly()
File as read-only and return true
if the operation was successful.public boolean mkdirs()
File.mkdirs().true if the directory was created, false otherwisepublic boolean markModified()
true if the file's modification time was updated, false otherwisepublic void bfSetId(loci.formats.ReaderWrapper reader)
throws loci.formats.FormatException,
java.io.IOException
ReaderWrapper.setId(String) for this file.reader - the BioFormats reader upon which to operateloci.formats.FormatException - passed up from ReaderWrapper.setId(String)java.io.IOException - passed up from ReaderWrapper.setId(String)public java.lang.String toString()
toString in class java.lang.Objectpublic ome.model.core.OriginalFile asOriginalFile(java.lang.String mimetype)
OriginalFile instance for the given
CheckedPath even if it doesn't exist. If it does exist, then
the size and hash will be properly set. Further, if it's a directory,
the mimetype passed in by the user must either be null, in which case
"Directory" will be used, or must be that correct value.mimetype - The mimetype to handle.public boolean equals(java.lang.Object object)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Object