Class FileTreeIterator


public class FileTreeIterator extends WorkingTreeIterator
Working directory iterator for standard Java IO.

This iterator uses the standard java.io package to read the specified working directory as part of a TreeWalk.

  • Field Details

    • directory

      protected final File directory
      the starting directory of this Iterator. All entries are located directly in this directory.
    • fs

      protected final FS fs
      the file system abstraction which will be necessary to perform certain file system operations.
    • fileModeStrategy

      protected final FileTreeIterator.FileModeStrategy fileModeStrategy
      the strategy used to compute the FileMode for a FileEntry. Can be used to control things such as whether to recurse into a directory or create a gitlink.
      Since:
      4.3
  • Constructor Details

    • FileTreeIterator

      public FileTreeIterator(Repository repo)
      Create a new iterator to traverse the work tree and its children.
      Parameters:
      repo - the repository whose working tree will be scanned.
    • FileTreeIterator

      public FileTreeIterator(Repository repo, FileTreeIterator.FileModeStrategy fileModeStrategy)
      Create a new iterator to traverse the work tree and its children.
      Parameters:
      repo - the repository whose working tree will be scanned.
      fileModeStrategy - the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.
      Since:
      4.3
    • FileTreeIterator

      public FileTreeIterator(File root, FS fs, WorkingTreeOptions options)
      Create a new iterator to traverse the given directory and its children.
      Parameters:
      root - the starting directory. This directory should correspond to the root of the repository.
      fs - the file system abstraction which will be necessary to perform certain file system operations.
      options - working tree options to be used
    • FileTreeIterator

      public FileTreeIterator(File root, FS fs, WorkingTreeOptions options, FileTreeIterator.FileModeStrategy fileModeStrategy)
      Create a new iterator to traverse the given directory and its children.
      Parameters:
      root - the starting directory. This directory should correspond to the root of the repository.
      fs - the file system abstraction which will be necessary to perform certain file system operations.
      options - working tree options to be used
      fileModeStrategy - the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.
      Since:
      4.3
    • FileTreeIterator

      protected FileTreeIterator(FileTreeIterator p, File root, FS fs)
      Create a new iterator to traverse a subdirectory.
      Parameters:
      p - the parent iterator we were created from.
      root - the subdirectory. This should be a directory contained within the parent directory.
      fs - the file system abstraction which will be necessary to perform certain file system operations.
      Since:
      4.3
    • FileTreeIterator

      protected FileTreeIterator(WorkingTreeIterator p, File root, FS fs, FileTreeIterator.FileModeStrategy fileModeStrategy)
      Create a new iterator to traverse a subdirectory, given the specified FileModeStrategy.
      Parameters:
      p - the parent iterator we were created from.
      root - the subdirectory. This should be a directory contained within the parent directory
      fs - the file system abstraction which will be necessary to perform certain file system operations.
      fileModeStrategy - the strategy to use to determine the FileMode for a given FileEntry.
      Since:
      4.3
  • Method Details

    • createSubtreeIterator

      public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException
      Create a new iterator for the current entry's subtree.

      The parent reference of the iterator must be this, otherwise the caller would not be able to exit out of the subtree iterator correctly and return to continue walking this.

      Specified by:
      createSubtreeIterator in class AbstractTreeIterator
      Parameters:
      reader - reader to load the tree data from.
      Returns:
      a new parser that walks over the current subtree.
      Throws:
      IncorrectObjectTypeException - the current entry is not actually a tree and cannot be parsed as though it were a tree.
      IOException - a loose object or pack file could not be read.
    • enterSubtree

      protected AbstractTreeIterator enterSubtree()
      Create a new iterator for the current entry's subtree.

      The parent reference of the iterator must be this, otherwise the caller would not be able to exit out of the subtree iterator correctly and return to continue walking this.

      Returns:
      a new iterator that walks over the current subtree.
      Since:
      5.0
    • entries

      private WorkingTreeIterator.Entry[] entries()
    • getDirectory

      public File getDirectory()

      Getter for the field directory.

      Returns:
      The root directory of this iterator
    • getEntryFile

      public File getEntryFile()
      Get the location of the working file.
      Returns:
      The location of the working file. This is the same as new File(getDirectory(), getEntryPath()) but may be faster by reusing an internal File instance.
    • idSubmodule

      protected byte[] idSubmodule(WorkingTreeIterator.Entry e)
      Get submodule id for given entry.
      Overrides:
      idSubmodule in class WorkingTreeIterator
      Parameters:
      e - a WorkingTreeIterator.Entry object.
      Returns:
      non-null submodule id
    • readSymlinkTarget

      protected String readSymlinkTarget(WorkingTreeIterator.Entry entry) throws IOException
      Reads the target of a symlink as a string. This default implementation fully reads the entry's input stream and converts it to a normalized string. Subclasses may override to provide more specialized implementations.
      Overrides:
      readSymlinkTarget in class WorkingTreeIterator
      Parameters:
      entry - to read
      Returns:
      the entry's content as a normalized string
      Throws:
      IOException - if the entry cannot be read or does not denote a symlink