Class TextFileSnapshot

  • All Implemented Interfaces:
    ISnapshot

    public final class TextFileSnapshot
    extends Snapshot
    A snapshot of a text IFile. Thread-safe.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  TextFileSnapshot.Layer
      Specifies whether the snapshot is to be taken directly from the file system, bypassing the workspace.
    • Constructor Summary

      Constructors 
      Constructor Description
      TextFileSnapshot​(org.eclipse.core.resources.IFile file, TextFileSnapshot.Layer layer)
      Constructs a new snapshot of the given text IFile.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean exists()
      Returns whether the file existed at the moment this snapshot was taken.
      java.lang.String getContents()
      A snapshot returns the same contents until it expires.
      org.eclipse.core.runtime.IStatus getStatus()
      Returns whether an I/O error was encountered while reading the file.
      protected java.lang.Boolean predictEquality​(Snapshot other)
      Predicts whether this snapshot is equal to the given snapshot without actually obtaining snapshot contents.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TextFileSnapshot

        public TextFileSnapshot​(org.eclipse.core.resources.IFile file,
                                TextFileSnapshot.Layer layer)
        Constructs a new snapshot of the given text IFile.

        The workspace may be out of sync with the file system. The layer argument controls how to deal with that. If Layer.FILESYSTEM is specified, the snapshot will be taken directly from the file system, bypassing the workspace. If Layer.WORKSPACE is specified, the snapshot will expire if the workspace is not in sync with the corresponding location in the file system.

        Parameters:
        file - not null
        layer - controls whether the snapshot is to be taken directly from the file system, bypassing the workspace
    • Method Detail

      • getContents

        public java.lang.String getContents()
        Description copied from interface: ISnapshot
        A snapshot returns the same contents until it expires. This is the contents of the underlying resource or buffer at the moment the snapshot was taken. Expired snapshots return null.

        Protractedly holding on to the returned contents is not recommended, as it may potentially consume significant amount of space.

        Returns:
        the contents of the snapshot, or null if the snapshot has expired
      • getStatus

        public org.eclipse.core.runtime.IStatus getStatus()
        Returns whether an I/O error was encountered while reading the file.
        Returns:
        an error status if an I/O error was encountered, or OK status otherwise
      • exists

        public boolean exists()
        Returns whether the file existed at the moment this snapshot was taken.
        Returns:
        true if the file existed at the moment this snapshot was taken, and false otherwise
      • predictEquality

        protected java.lang.Boolean predictEquality​(Snapshot other)
        Description copied from class: Snapshot
        Predicts whether this snapshot is equal to the given snapshot without actually obtaining snapshot contents. Must return null if cannot tell for sure. Any non-null result must meet the contract of ISnapshot.isEqualTo(ISnapshot).
        Overrides:
        predictEquality in class Snapshot
        Parameters:
        other - the other snapshot (not null and not identical to the receiver)
        Returns:
        true if the snapshots are predicted to be equal, false if the snapshots are predicted to be unequal, and null if there is no prediction