Class File

java.lang.Object
com.google.common.jimfs.File
Direct Known Subclasses:
Directory, RegularFile, SymbolicLink

public abstract class File extends Object
A file object, containing both the file's metadata and content.
  • Field Details

    • id

      private final int id
    • creationTime

      private FileTime creationTime
    • lastAccessTime

      private FileTime lastAccessTime
    • lastModifiedTime

      private FileTime lastModifiedTime
    • attributes

      private @Nullable com.google.common.collect.Table<String,String,Object> attributes
  • Constructor Details

    • File

      File(int id, FileTime creationTime)
  • Method Details

    • id

      public int id()
      Returns the ID of this file.
    • size

      public long size()
      Returns the size, in bytes, of this file's content. Directories and symbolic links have a size of 0.
    • isDirectory

      public final boolean isDirectory()
      Returns whether or not this file is a directory.
    • isRegularFile

      public final boolean isRegularFile()
      Returns whether or not this file is a regular file.
    • isSymbolicLink

      public final boolean isSymbolicLink()
      Returns whether or not this file is a symbolic link.
    • copyWithoutContent

      abstract File copyWithoutContent(int id, FileTime creationTime)
      Creates a new file of the same type as this file with the given ID and creation time. Does not copy the content of this file unless the cost of copying the content is minimal. This is because this method is called with a hold on the file system's lock.
    • copyContentTo

      void copyContentTo(File file) throws IOException
      Copies the content of this file to the given file. The given file must be the same type of file as this file and should have no content.

      This method is used for copying the content of a file after copying the file itself. Does nothing by default.

      Throws:
      IOException
    • contentLock

      @Nullable ReadWriteLock contentLock()
      Returns the read-write lock for this file's content, or null if there is no content lock.
    • opened

      void opened()
      Called when a stream or channel to this file is opened.
    • closed

      void closed()
      Called when a stream or channel to this file is closed. If there are no more streams or channels open to the file and it has been deleted, its contents may be deleted.
    • deleted

      void deleted()
      Called when (a single link to) this file is deleted. There may be links remaining. Does nothing by default.
    • isRootDirectory

      final boolean isRootDirectory()
      Returns whether or not this file is a root directory of the file system.
    • links

      public final int links()
      Returns the current count of links to this file.
    • linked

      void linked(DirectoryEntry entry)
      Called when this file has been linked in a directory. The given entry is the new directory entry that links to this file.
    • unlinked

      void unlinked()
      Called when this file has been unlinked from a directory, either for a move or delete.
    • incrementLinkCount

      final void incrementLinkCount()
      Increments the link count for this file.
    • decrementLinkCount

      final void decrementLinkCount()
      Decrements the link count for this file.
    • getCreationTime

      public final FileTime getCreationTime()
      Gets the creation time of the file.
    • getLastAccessTime

      public final FileTime getLastAccessTime()
      Gets the last access time of the file.
    • getLastModifiedTime

      public final FileTime getLastModifiedTime()
      Gets the last modified time of the file.
    • setCreationTime

      final void setCreationTime(FileTime creationTime)
      Sets the creation time of the file.
    • setLastAccessTime

      final void setLastAccessTime(FileTime lastAccessTime)
      Sets the last access time of the file.
    • setLastModifiedTime

      final void setLastModifiedTime(FileTime lastModifiedTime)
      Sets the last modified time of the file.
    • getAttributeNames

      public final com.google.common.collect.ImmutableSet<String> getAttributeNames(String view)
      Returns the names of the attributes contained in the given attribute view in the file's attributes table.
    • getAttributeKeys

      final com.google.common.collect.ImmutableSet<String> getAttributeKeys()
      Returns the attribute keys contained in the attributes map for the file.
    • getAttribute

      public final @Nullable Object getAttribute(String view, String attribute)
      Gets the value of the given attribute in the given view.
    • setAttribute

      public final void setAttribute(String view, String attribute, Object value)
      Sets the given attribute in the given view to the given value.
    • deleteAttribute

      public final void deleteAttribute(String view, String attribute)
      Deletes the given attribute from the given view.
    • copyBasicAttributes

      final void copyBasicAttributes(File target)
      Copies basic attributes (file times) from this file to the given file.
    • setFileTimes

      private void setFileTimes(FileTime creationTime, FileTime lastModifiedTime, FileTime lastAccessTime)
    • copyAttributes

      final void copyAttributes(File target)
      Copies the attributes from this file to the given file.
    • putAll

      private void putAll(@Nullable com.google.common.collect.Table<String,String,Object> attributes)
    • toString

      public final String toString()
      Overrides:
      toString in class Object