Package ome.services.blitz.repo
Class CheckedPath
- java.lang.Object
-
- ome.services.blitz.repo.CheckedPath
-
public class CheckedPath extends java.lang.ObjectTo prevent frequently re-calculating paths and re-creating File objects,CheckedPathobjects store various interpretations of paths that are passed in by users. One of these objects should be created at the very beginning of anyPublicRepositoryIremote method (i.e. those public methods which takeCurrentinstance arguments. Methods are then available to check various capabilities by the current user. When a nullCheckedPathobject is passed into the constructor the caller indicates that the path is the root path, henceisRootwill not be called.
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ome.model.core.OriginalFileasOriginalFile(java.lang.String mimetype)Creates anOriginalFileinstance for the givenCheckedPatheven if it doesn't exist.voidbfSetId(loci.formats.ReaderWrapper reader)Perform BioFormatsReaderWrapper.setId(String)for this file.booleancanEdit()booleancanRead()Check if this file is actually readable on the underlying filesystem.CheckedPathchild(java.lang.String name)Returns a newCheckedPaththat has the given path appended to the end of this instances path.booleanequals(java.lang.Object object)Instances are equal if their string representations match.booleanexists()Check if this file actually exists on the underlying filesystem.protected java.lang.StringgetDirname()Assuming this is a directory, return relative path plus name with a final slash.ome.io.nio.FileBuffergetFileBuffer(java.lang.String mode)Get aFileBuffercorresponding to this instance.protected java.lang.StringgetFullFsPath()The full path of the entity to which this path corresponds.java.lang.LonggetId()java.lang.StringgetMimetype()Get the mimetype for a file.protected java.lang.StringgetName()Get the last component of this path, the entity to which the path corresponds.protected java.lang.StringgetRelativePath()Get the parent path of the entity to which this path corresponds.java.lang.Stringhash()inthashCode()On Windows systems the calculation is not case-sensitive.booleanisDirectory()booleanmarkModified()Mark this existing file as having been modified at the present moment.booleanmkdir()Create this directory on the underlying filesystem.booleanmkdirs()Create this directory, and parents if necessary, on the underlying filesystem.CheckedPathmustEdit()CheckedPathmustExist()Checks for existence of the original path, throwing an exception if not present.CheckedPathparent()Returns a newCheckedPathusingFile.getParent()and passing in all other values.voidsetId(java.lang.Long id)booleansetReadOnly()Mark the underlyingFileas read-only and return true if the operation was successful.longsize()Return the size of this file on the underlying filesystem.java.lang.StringtoString()
-
-
-
Field Detail
-
fsFile
public final FsFile fsFile
-
isRoot
public boolean isRoot
-
id
protected java.lang.Long id
-
hash
protected java.lang.String hash
-
mime
protected java.lang.String mime
-
-
Constructor Detail
-
CheckedPath
public CheckedPath(ServerFilePathTransformer serverPaths, java.lang.String path, ome.util.checksum.ChecksumProviderFactory checksumProviderFactory, ChecksumAlgorithm checksumAlgorithm) throws ValidationException
Construct a CheckedPath from a relative "/"-delimited path rooted at the repository. The path may not contain weird or special-meaning path components, though.
and..
are understood to have their usual meaning. An empty path is the repository root.- Parameters:
serverPaths- the server path handling servicepath- a repository pathchecksumProviderFactory- a source of checksum providers, may benullifchecksumAlgorithmis alsonullchecksumAlgorithm- the algorithm to use inhash()'s calculations- Throws:
ValidationException- if the path is empty or contains illegal components
-
-
Method Detail
-
getId
public java.lang.Long getId()
-
setId
public void setId(java.lang.Long id)
-
hash
public java.lang.String hash()
-
getMimetype
public java.lang.String getMimetype()
Get the mimetype for a file.- Returns:
- A String representing the mimetype.
-
parent
public CheckedPath parent() throws ValidationException
Returns a newCheckedPathusingFile.getParent()and passing in all other values. Just as if calling the constructor, bad paths will cause aValidationExceptionto be thrown.CheckedPaths generated with this method always return anullhash.- Throws:
ValidationException
-
child
public CheckedPath child(java.lang.String name) throws ValidationException
Returns a newCheckedPaththat 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 anullhash.- Parameters:
name-- Returns:
- See above.
- Throws:
ValidationException
-
exists
public boolean exists()
Check if this file actually exists on the underlying filesystem. Analogous toFile.exists().- Returns:
trueif the file exists,falseotherwise
-
mustExist
public CheckedPath mustExist() throws ValidationException
Checks for existence of the original path, throwing an exception if not present.- Returns:
- this instance for chaining.
- Throws:
ValidationException
-
mustEdit
public CheckedPath mustEdit() throws SecurityViolation
- Returns:
- this instance for chaining
- Throws:
SecurityViolation
-
canRead
public boolean canRead()
Check if this file is actually readable on the underlying filesystem. Analogous toFile.canRead().- Returns:
trueif the file is readable,falseotherwise
-
canEdit
public boolean canEdit()
-
isDirectory
public boolean isDirectory()
-
getDirname
protected java.lang.String getDirname()
Assuming this is a directory, return relative path plus name with a final slash.
-
getName
protected java.lang.String getName()
Get the last component of this path, the entity to which the path corresponds. If this entityisRootthen this is the empty string.- Returns:
- the last path component
-
getRelativePath
protected java.lang.String getRelativePath()
Get the parent path of the entity to which this path corresponds. If this entity is not in some sub-directory below root, then this relative path is just theFsFile.separatorChar.- Returns:
- the path components above the last,
with separators including a trailing
FsFile.separatorChar.
-
getFullFsPath
protected java.lang.String getFullFsPath()
The full path of the entity to which this path corresponds. Path components are separated byFsFile.separatorChar.- Returns:
- the full path
-
getFileBuffer
public ome.io.nio.FileBuffer getFileBuffer(java.lang.String mode)
Get aFileBuffercorresponding to this instance. It is the caller's responsibility toFileBuffer.close()it.- Parameters:
mode- as forRandomAccessFile(File, String),"r"and"rw"being common choices- Returns:
- a new
FileBuffer
-
size
public long size()
Return the size of this file on the underlying filesystem. Analogous toFile.length().- Returns:
- the file size
-
mkdir
public boolean mkdir()
Create this directory on the underlying filesystem. Analogous toFile.mkdir().- Returns:
trueif the directory was created,falseotherwise
-
setReadOnly
public boolean setReadOnly()
Mark the underlyingFileas read-only and return true if the operation was successful.
-
mkdirs
public boolean mkdirs()
Create this directory, and parents if necessary, on the underlying filesystem. Analogous toFile.mkdirs().- Returns:
trueif the directory was created,falseotherwise
-
markModified
public boolean markModified()
Mark this existing file as having been modified at the present moment.- Returns:
trueif the file's modification time was updated,falseotherwise
-
bfSetId
public void bfSetId(loci.formats.ReaderWrapper reader) throws loci.formats.FormatException, java.io.IOExceptionPerform BioFormatsReaderWrapper.setId(String)for this file.- Parameters:
reader- the BioFormats reader upon which to operate- Throws:
loci.formats.FormatException- passed up fromReaderWrapper.setId(String)java.io.IOException- passed up fromReaderWrapper.setId(String)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
asOriginalFile
public ome.model.core.OriginalFile asOriginalFile(java.lang.String mimetype)
Creates anOriginalFileinstance for the givenCheckedPatheven 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.- Parameters:
mimetype- The mimetype to handle.- Returns:
- See above.
-
equals
public boolean equals(java.lang.Object object)
Instances are equal if their string representations match. On Windows systems the comparison is not case-sensitive.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
On Windows systems the calculation is not case-sensitive.- Overrides:
hashCodein classjava.lang.Object
-
-