Top Description Inners Fields Constructors Methods
org.eclipse.jgit.treewalk

public Class FileTreeIterator

extends WorkingTreeIterator
Class Inheritance
Static Imports
java.nio.charset.StandardCharsets.UTF_8

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 org.eclipse.jgit.treewalk.TreeWalk.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
FileTreeIterator.DefaultFileModeStrategy

A default implementation of a FileModeStrategy; defaults to treating nested .git directories as gitlinks, etc.

public static class
FileTreeIterator.FileEntry

Wrapper for a standard Java IO file

public static interface
FileTreeIterator.FileModeStrategy

An interface representing the methods used to determine the FileMode for a FileEntry.

public static class
FileTreeIterator.NoGitlinksStrategy

A FileModeStrategy that implements native git's DIR_NO_GITLINKS behavior.

Field Summary

Modifier and TypeField and Description
protected final File
directory

the starting directory of this Iterator.

protected final FileTreeIterator.FileModeStrategy
fileModeStrategy

the strategy used to compute the FileMode for a FileEntry.

protected final FS
fs

the file system abstraction which will be necessary to perform certain file system operations.

Inherited from org.eclipse.jgit.treewalk.WorkingTreeIterator:
BUFFER_SIZEEOFrepository

Constructor Summary

AccessConstructor and Description
public
FileTreeIterator(Repository
the repository whose working tree will be scanned.
repo
)

Create a new iterator to traverse the work tree and its children.

public
FileTreeIterator(Repository
the repository whose working tree will be scanned.
repo
,
FileTreeIterator.FileModeStrategy
the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.
fileModeStrategy
)

Create a new iterator to traverse the work tree and its children.

public
FileTreeIterator(File
the starting directory. This directory should correspond to the root of the repository.
root
,
FS
the file system abstraction which will be necessary to perform certain file system operations.
fs
,
WorkingTreeOptions
working tree options to be used
options
)

Create a new iterator to traverse the given directory and its children.

public
FileTreeIterator(final File
the starting directory. This directory should correspond to the root of the repository.
root
,
FS
the file system abstraction which will be necessary to perform certain file system operations.
fs
,
WorkingTreeOptions
working tree options to be used
options
,
FileTreeIterator.FileModeStrategy
the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.
fileModeStrategy
)

Create a new iterator to traverse the given directory and its children.

protected
FileTreeIterator(final FileTreeIterator
the parent iterator we were created from.
p
,
final File
the subdirectory. This should be a directory contained within the parent directory.
root
,
FS
the file system abstraction which will be necessary to perform certain file system operations.
fs
)

Create a new iterator to traverse a subdirectory.

protected
FileTreeIterator(final WorkingTreeIterator
the parent iterator we were created from.
p
,
final File
the subdirectory. This should be a directory contained within the parent directory
root
,
FS
the file system abstraction which will be necessary to perform certain file system operations.
fs
,
FileTreeIterator.FileModeStrategy
the strategy to use to determine the FileMode for a given FileEntry.
fileModeStrategy
)

Create a new iterator to traverse a subdirectory, given the specified FileModeStrategy.

Method Summary

Modifier and TypeMethod and Description
public AbstractTreeIterator
createSubtreeIterator(ObjectReader
reader to load the tree data from.
reader
)

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

Create a new iterator for the current entry's subtree.

protected AbstractTreeIterator

Returns:

a new iterator that walks over the current subtree.
enterSubtree
()

Create a new iterator for the current entry's subtree.

private WorkingTreeIterator.Entry[]
public File

Returns:

The root directory of this iterator
getDirectory
()

Getter for the field directory.

public 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.
getEntryFile
()

Get the location of the working file.

protected byte[]
protected String
readSymlinkTarget(WorkingTreeIterator.Entry
to read
entry
)

Overrides org.eclipse.jgit.treewalk.WorkingTreeIterator.readSymlinkTarget.

Reads the target of a symlink as a string.

Inherited from org.eclipse.jgit.treewalk.WorkingTreeIterator:
backcompareMetadatacurrenteoffirstgetCleanFilterCommandgetDirCacheIteratorgetEntryAttributesNodegetEntryContentLengthgetEntryLastModifiedInstantgetEntryLengthgetEolStreamTypegetIndexFileModegetOptionsgetRepositoryhasIdidBufferidOffsetidSubmoduleinitinitRootIteratorisEntryIgnoredisEntryIgnoredisModeDifferentisModifiedisWorkTreenextopenEntryStreamresetsetDirCacheIteratorsetWalkIgnoredDirectorieswalksIgnoredDirectories

Field Detail

directoryback to summary
protected final File directory

the starting directory of this Iterator. All entries are located directly in this directory.

fileModeStrategyback to summary
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
fsback to summary
protected final FS fs

the file system abstraction which will be necessary to perform certain file system operations.

Constructor Detail

FileTreeIteratorback to summary
public FileTreeIterator(Repository repo)

Create a new iterator to traverse the work tree and its children.

Parameters
repo:Repository

the repository whose working tree will be scanned.

FileTreeIteratorback to summary
public FileTreeIterator(Repository repo, FileTreeIterator.FileModeStrategy fileModeStrategy)

Create a new iterator to traverse the work tree and its children.

Parameters
repo:Repository

the repository whose working tree will be scanned.

fileModeStrategy:FileTreeIterator.FileModeStrategy

the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.

Since
4.3
FileTreeIteratorback to summary
public FileTreeIterator(File root, FS fs, WorkingTreeOptions options)

Create a new iterator to traverse the given directory and its children.

Parameters
root:File

the starting directory. This directory should correspond to the root of the repository.

fs:FS

the file system abstraction which will be necessary to perform certain file system operations.

options:WorkingTreeOptions

working tree options to be used

FileTreeIteratorback to summary
public FileTreeIterator(final File root, FS fs, WorkingTreeOptions options, FileTreeIterator.FileModeStrategy fileModeStrategy)

Create a new iterator to traverse the given directory and its children.

Parameters
root:File

the starting directory. This directory should correspond to the root of the repository.

fs:FS

the file system abstraction which will be necessary to perform certain file system operations.

options:WorkingTreeOptions

working tree options to be used

fileModeStrategy:FileTreeIterator.FileModeStrategy

the strategy to use to determine the FileMode for a FileEntry; controls gitlinks etc.

Since
4.3
FileTreeIteratorback to summary
protected FileTreeIterator(final FileTreeIterator p, final File root, FS fs)

Create a new iterator to traverse a subdirectory.

Parameters
p:FileTreeIterator

the parent iterator we were created from.

root:File

the subdirectory. This should be a directory contained within the parent directory.

fs:FS

the file system abstraction which will be necessary to perform certain file system operations.

Since
4.3
FileTreeIteratorback to summary
protected FileTreeIterator(final WorkingTreeIterator p, final File root, FS fs, FileTreeIterator.FileModeStrategy fileModeStrategy)

Create a new iterator to traverse a subdirectory, given the specified FileModeStrategy.

Parameters
p:WorkingTreeIterator

the parent iterator we were created from.

root:File

the subdirectory. This should be a directory contained within the parent directory

fs:FS

the file system abstraction which will be necessary to perform certain file system operations.

fileModeStrategy:FileTreeIterator.FileModeStrategy

the strategy to use to determine the FileMode for a given FileEntry.

Since
4.3

Method Detail

createSubtreeIteratorback to summary
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) throws IncorrectObjectTypeException, IOException

Implements abstract org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

Doc from org.eclipse.jgit.treewalk.AbstractTreeIterator.createSubtreeIterator.

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.

Parameters
reader:ObjectReader

reader to load the tree data from.

Returns:AbstractTreeIterator

a new parser that walks over the current subtree.

Annotations
@Override
Exceptions
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.
enterSubtreeback to summary
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:AbstractTreeIterator

a new iterator that walks over the current subtree.

Since
5.0
entriesback to summary
private WorkingTreeIterator.Entry[] entries()
getDirectoryback to summary
public File getDirectory()

Getter for the field directory.

Returns:File

The root directory of this iterator

getEntryFileback to summary
public File getEntryFile()

Get the location of the working file.

Returns:File

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.

idSubmoduleback to summary
protected byte[] idSubmodule(WorkingTreeIterator.Entry e)

Overrides org.eclipse.jgit.treewalk.WorkingTreeIterator.idSubmodule.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.idSubmodule.

Get submodule id for given entry.

Parameters
e:WorkingTreeIterator.Entry

a org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry object.

Returns:byte[]

non-null submodule id

Annotations
@Override
readSymlinkTargetback to summary
protected String readSymlinkTarget(WorkingTreeIterator.Entry entry) throws IOException

Overrides org.eclipse.jgit.treewalk.WorkingTreeIterator.readSymlinkTarget.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.readSymlinkTarget.

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.

Parameters
entry:WorkingTreeIterator.Entry

to read

Returns:String

the entry's content as a normalized string

Annotations
@Override
Exceptions
IOException:
if the entry cannot be read or does not denote a symlink
org.eclipse.jgit.treewalk back to summary

public Class FileTreeIterator.DefaultFileModeStrategy

extends Object
implements FileModeStrategy
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.treewalk.FileTreeIterator.DefaultFileModeStrategy
All Implemented Interfaces
org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy

A default implementation of a FileModeStrategy; defaults to treating nested .git directories as gitlinks, etc.
Since
4.3

Field Summary

Modifier and TypeField and Description
public static final FileTreeIterator.DefaultFileModeStrategy
INSTANCE

a singleton instance of the default FileModeStrategy

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public FileMode
getMode(File
the file to return a FileMode for
f
,
FS.Attributes
the attributes of a file
attributes
)

Implements org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Compute the FileMode for a given File, based on its attributes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final FileTreeIterator.DefaultFileModeStrategy INSTANCE

a singleton instance of the default FileModeStrategy

Constructor Detail

DefaultFileModeStrategyback to summary
public DefaultFileModeStrategy()

Method Detail

getModeback to summary
public FileMode getMode(File f, FS.Attributes attributes)

Implements org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Doc from org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Compute the FileMode for a given File, based on its attributes.

Parameters
f:File

the file to return a FileMode for

attributes:FS.Attributes

the attributes of a file

Returns:FileMode

a FileMode indicating whether the file is a regular file, a directory, a gitlink, etc.

Annotations
@Override
org.eclipse.jgit.treewalk back to summary

public Class FileTreeIterator.FileEntry

extends Entry
Class Inheritance

Wrapper for a standard Java IO file

Field Summary

Modifier and TypeField and Description
private FS.Attributes
private FS
private final FileMode
Inherited from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry:
encodedNameencodedNameLen

Constructor Summary

AccessConstructor and Description
public
FileEntry(File
file
f
,
FS
file system
fs
)

Create a new file entry.

public
FileEntry(File
file
f
,
FS
file system
fs
,
FileTreeIterator.FileModeStrategy
the strategy to use when determining the FileMode of a file; controls gitlinks etc.
fileModeStrategy
)

Create a new file entry given the specified FileModeStrategy

public
FileEntry(File
file
f
,
FS
file system
fs
,
FS.Attributes
of the file
attributes
,
FileTreeIterator.FileModeStrategy
the strategy to use when determining the FileMode of a file; controls gitlinks etc.
fileModeStrategy
)

Create a new file entry given the specified FileModeStrategy

Method Summary

Modifier and TypeMethod and Description
public File

Returns:

the underlying file of this entry
getFile
()

Get the underlying file of this entry.

public Instant
getLastModifiedInstant()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLastModifiedInstant.

Get the last modified time of this entry.

public long
getLength()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLength.

Get the byte length of this entry.

public FileMode
getMode()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getMode.

Get the type of this entry.

public String
getName()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getName.

Get the name of this entry within its directory.

public InputStream
openInputStream()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.openInputStream.

Obtain an input stream to read the file content.

Inherited from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry:
encodeNametoString

Field Detail

attributesback to summary
private FS.Attributes attributes
fsback to summary
private FS fs
modeback to summary
private final FileMode mode

Constructor Detail

FileEntryback to summary
public FileEntry(File f, FS fs)

Create a new file entry.

Parameters
f:File

file

fs:FS

file system

FileEntryback to summary
public FileEntry(File f, FS fs, FileTreeIterator.FileModeStrategy fileModeStrategy)

Create a new file entry given the specified FileModeStrategy

Parameters
f:File

file

fs:FS

file system

fileModeStrategy:FileTreeIterator.FileModeStrategy

the strategy to use when determining the FileMode of a file; controls gitlinks etc.

Since
4.3
FileEntryback to summary
public FileEntry(File f, FS fs, FS.Attributes attributes, FileTreeIterator.FileModeStrategy fileModeStrategy)

Create a new file entry given the specified FileModeStrategy

Parameters
f:File

file

fs:FS

file system

attributes:FS.Attributes

of the file

fileModeStrategy:FileTreeIterator.FileModeStrategy

the strategy to use when determining the FileMode of a file; controls gitlinks etc.

Since
5.0

Method Detail

getFileback to summary
public File getFile()

Get the underlying file of this entry.

Returns:File

the underlying file of this entry

getLastModifiedInstantback to summary
public Instant getLastModifiedInstant()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLastModifiedInstant.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLastModifiedInstant.

Get the last modified time of this entry.

Note

Efficient implementation required.

The implementation of this method must be efficient. If a subclass needs to compute the value they should cache the reference within an instance member instead.

Returns:Instant

time of the last change.

Annotations
@Override
Since
5.1.9
getLengthback to summary
public long getLength()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLength.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getLength.

Get the byte length of this entry.

Note

Efficient implementation required.

The implementation of this method must be efficient. If a subclass needs to compute the value they should cache the reference within an instance member instead.

Returns:long

size of this file, in bytes.

Annotations
@Override
getModeback to summary
public FileMode getMode()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getMode.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getMode.

Get the type of this entry.

Note

Efficient implementation required.

The implementation of this method must be efficient. If a subclass needs to compute the value they should cache the reference within an instance member instead.

Returns:FileMode

a file mode constant from FileMode.

Annotations
@Override
getNameback to summary
public String getName()

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getName.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.getName.

Get the name of this entry within its directory.

Efficient implementations are not required. The caller will obtain the name only once and cache it once obtained.

Returns:String

name of the entry.

Annotations
@Override
openInputStreamback to summary
public InputStream openInputStream() throws IOException

Implements abstract org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.openInputStream.

Doc from org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry.openInputStream.

Obtain an input stream to read the file content.

Efficient implementations are not required. The caller will usually obtain the stream only once per entry, if at all.

The input stream should not use buffering if the implementation can avoid it. The caller will buffer as necessary to perform efficient block IO operations.

The caller will close the stream once complete.

Returns:InputStream

a stream to read from the file.

Annotations
@Override
Exceptions
IOException:
the file could not be opened for reading.
org.eclipse.jgit.treewalk back to summary

public Interface FileTreeIterator.FileModeStrategy

Known Direct Implementers
org.eclipse.jgit.treewalk.FileTreeIterator.DefaultFileModeStrategy, org.eclipse.jgit.treewalk.FileTreeIterator.NoGitlinksStrategy

An interface representing the methods used to determine the FileMode for a FileEntry.
Since
4.3

Method Summary

Modifier and TypeMethod and Description
public FileMode

Returns:

a FileMode indicating whether the file is a regular file, a directory, a gitlink, etc.
getMode
(File
the file to return a FileMode for
f
,
FS.Attributes
the attributes of a file
attributes
)

Compute the FileMode for a given File, based on its attributes.

Method Detail

getModeback to summary
public FileMode getMode(File f, FS.Attributes attributes)

Compute the FileMode for a given File, based on its attributes.

Parameters
f:File

the file to return a FileMode for

attributes:FS.Attributes

the attributes of a file

Returns:FileMode

a FileMode indicating whether the file is a regular file, a directory, a gitlink, etc.

org.eclipse.jgit.treewalk back to summary

public Class FileTreeIterator.NoGitlinksStrategy

extends Object
implements FileModeStrategy
Class Inheritance
  • java.lang.Object
  • org.eclipse.jgit.treewalk.FileTreeIterator.NoGitlinksStrategy
All Implemented Interfaces
org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy

A FileModeStrategy that implements native git's DIR_NO_GITLINKS behavior. This is the same as the default FileModeStrategy, except all directories will be treated as directories regardless of whether or not they contain a .git directory or file.
Since
4.3

Field Summary

Modifier and TypeField and Description
public static final FileTreeIterator.NoGitlinksStrategy
INSTANCE

a singleton instance of the default FileModeStrategy

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public FileMode
getMode(File
the file to return a FileMode for
f
,
FS.Attributes
the attributes of a file
attributes
)

Implements org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Compute the FileMode for a given File, based on its attributes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

INSTANCEback to summary
public static final FileTreeIterator.NoGitlinksStrategy INSTANCE

a singleton instance of the default FileModeStrategy

Constructor Detail

NoGitlinksStrategyback to summary
public NoGitlinksStrategy()

Method Detail

getModeback to summary
public FileMode getMode(File f, FS.Attributes attributes)

Implements org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Doc from org.eclipse.jgit.treewalk.FileTreeIterator.FileModeStrategy.getMode.

Compute the FileMode for a given File, based on its attributes.

Parameters
f:File

the file to return a FileMode for

attributes:FS.Attributes

the attributes of a file

Returns:FileMode

a FileMode indicating whether the file is a regular file, a directory, a gitlink, etc.

Annotations
@Override