Class MCRNode

java.lang.Object
org.mycore.datamodel.ifs2.MCRNode
Direct Known Subclasses:
MCRStoredNode, MCRVirtualNode

public abstract class MCRNode extends Object
Represents a file, directory or file collection within a file store. Files and directories can be either really stored, or virtually existing as a child node contained within a stored container file like zip or tar.
Author:
Frank Lützenkirchen
  • Field Details

    • path

      protected Path path
      The path object representing this node in the underlying filesystem.
    • parent

      protected MCRNode parent
      The parent node owning this file, a directory or container file
  • Constructor Details

    • MCRNode

      protected MCRNode(MCRNode parent, Path path)
      Creates a new node representing a child of the given parent
      Parameters:
      parent - the parent node
      path - the file object representing this node in the underlying filesystem
  • Method Details

    • getName

      public String getName()
      Returns the file or directory name
      Returns:
      the node's filename
    • getPath

      public String getPath()
      Returns the complete path of this node up to the root file collection. Path always start with a slash, slash is used as directory delimiter.
      Returns:
      the absolute path of this node
    • getParent

      public MCRNode getParent()
      Returns the parent node containing this node
      Returns:
      the parent directory or container file
    • getRoot

      public MCRFileCollection getRoot()
      Returns the root file collection this node belongs to
      Returns:
      the root file collection
    • isFile

      public boolean isFile() throws IOException
      Returns true if this node is a file
      Returns:
      true if this node is a file
      Throws:
      IOException
    • isDirectory

      public boolean isDirectory() throws IOException
      Returns true if this node is a directory
      Returns:
      true if this node is a directory
      Throws:
      IOException
    • getSize

      public long getSize() throws IOException
      For file nodes, returns the file content size in bytes, otherwise returns 0.
      Returns:
      the file size in bytes
      Throws:
      IOException
    • getLastModified

      public Date getLastModified() throws IOException
      Returns the time this node was last modified.
      Returns:
      the time this node was last modified
      Throws:
      IOException
    • hasChildren

      public boolean hasChildren() throws IOException
      Returns true if this node has child nodes. Directories and container files like zip or tar may have child nodes.
      Returns:
      true if children exist
      Throws:
      IOException
    • getNumChildren

      public int getNumChildren() throws IOException
      Returns the number of child nodes of this node.
      Returns:
      the number of child nodes of this node.
      Throws:
      IOException
    • getChildren

      public Stream<MCRNode> getChildren() throws IOException
      Returns the children of this node.
      Returns:
      a List of child nodes, which may be empty, in undefined order
      Throws:
      IOException
    • buildChildNode

      protected abstract MCRNode buildChildNode(Path fo)
      Creates a node instance for the given FileObject, which represents the child
      Parameters:
      fo - the FileObject representing the child in the underlying filesystem
      Returns:
      the child node or null, if the fo does not exists
      Throws:
      IllegalArgumentException - if fo is not valid path for a child of this
    • getChild

      public MCRNode getChild(String name)
      Returns the child node with the given filename, or null
      Parameters:
      name - the name of the child node
      Returns:
      the child node with that name, or null when no such file exists
    • getNodeByPath

      public MCRNode getNodeByPath(String path) throws IOException
      Returns the node with the given relative or absolute path in the file collection this node belongs to. Slash is used as directory delimiter. When the path starts with a slash, it is an absolute path and resolving is startet at the root file collection. When the path is relative, resolving starts with the current node. One dot represents the current node, Two dots represent the parent node, like in paths used by typical real filesystems.
      Parameters:
      path - the absolute or relative path of the node to find, may contain . or ..
      Returns:
      the node at the given path, or null
      Throws:
      IOException
    • getContent

      public MCRContent getContent() throws IOException
      Returns the content of this node for output. For a directory, it will return null.
      Returns:
      the content of the file
      Throws:
      IOException
    • getRandomAccessContent

      public SeekableByteChannel getRandomAccessContent() throws IOException
      Returns the content of this node for random access read. Be sure not to write to the node using the returned object, use just for reading! For a directory, it will return null.
      Returns:
      the content of this file, for random access
      Throws:
      IOException