Class CheckedPath


  • public class CheckedPath
    extends java.lang.Object
    To prevent frequently re-calculating paths and re-creating File objects, 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.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      FsFile fsFile  
      protected java.lang.String hash  
      protected java.lang.Long id  
      boolean isRoot  
      protected java.lang.String mime  
    • 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.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()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • 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 service
        path - a repository path
        checksumProviderFactory - a source of checksum providers, may be null if checksumAlgorithm is also null
        checksumAlgorithm - the algorithm to use in hash()'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.
      • child

        public CheckedPath child​(java.lang.String name)
                          throws ValidationException
        Returns a new 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.
        Parameters:
        name -
        Returns:
        See above.
        Throws:
        ValidationException
      • exists

        public boolean exists()
        Check if this file actually exists on the underlying filesystem. Analogous to File.exists().
        Returns:
        true if the file exists, false otherwise
      • canRead

        public boolean canRead()
        Check if this file is actually readable on the underlying filesystem. Analogous to File.canRead().
        Returns:
        true if the file is readable, false otherwise
      • 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 entity isRoot then 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 the FsFile.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 by FsFile.separatorChar.
        Returns:
        the full path
      • getFileBuffer

        public ome.io.nio.FileBuffer getFileBuffer​(java.lang.String mode)
        Get a FileBuffer corresponding to this instance. It is the caller's responsibility to FileBuffer.close() it.
        Parameters:
        mode - as for RandomAccessFile(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 to File.length().
        Returns:
        the file size
      • mkdir

        public boolean mkdir()
        Create this directory on the underlying filesystem. Analogous to File.mkdir().
        Returns:
        true if the directory was created, false otherwise
      • setReadOnly

        public boolean setReadOnly()
        Mark the underlying File as 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 to File.mkdirs().
        Returns:
        true if the directory was created, false otherwise
      • markModified

        public boolean markModified()
        Mark this existing file as having been modified at the present moment.
        Returns:
        true if the file's modification time was updated, false otherwise
      • bfSetId

        public void bfSetId​(loci.formats.ReaderWrapper reader)
                     throws loci.formats.FormatException,
                            java.io.IOException
        Perform BioFormats ReaderWrapper.setId(String) for this file.
        Parameters:
        reader - the BioFormats reader upon which to operate
        Throws:
        loci.formats.FormatException - passed up from ReaderWrapper.setId(String)
        java.io.IOException - passed up from ReaderWrapper.setId(String)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • asOriginalFile

        public ome.model.core.OriginalFile asOriginalFile​(java.lang.String mimetype)
        Creates an 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.
        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:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        On Windows systems the calculation is not case-sensitive.
        Overrides:
        hashCode in class java.lang.Object