Top Description Inners Fields Constructors Methods
java.nio.file

pack-priv Class FileTreeWalker

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Imports
java.nio.file.attribute.BasicFileAttributes, java.io.Closeable, .IOException, java.util.ArrayDeque, .Collection, .Iterator, sun.nio.fs.BasicFileAttributesHolder

Walks a file tree, generating a sequence of events corresponding to the files in the tree.
Path top = ... Set<FileVisitOption> options = ... int maxDepth = ... try (FileTreeWalker walker = new FileTreeWalker(options, maxDepth)) { FileTreeWalker.Event ev = walker.walk(top); do { process(ev); ev = walker.next(); } while (ev != null); }
Path top = ...
Set<FileVisitOption> options = ...
int maxDepth = ...

try (FileTreeWalker walker = new FileTreeWalker(options, maxDepth)) {
    FileTreeWalker.Event ev = walker.walk(top);
    do {
        process(ev);
        ev = walker.next();
    } while (ev != null);
}
See Also
Files#walkFileTree

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
FileTreeWalker.DirectoryNode

The element on the walking stack corresponding to a directory node.

pack-priv static class
FileTreeWalker.Event

Events returned by the walk and next methods.

pack-priv static enum
FileTreeWalker.EventType

The event types.

Field Summary

Modifier and TypeField and Description
private boolean
private final boolean
private final LinkOption[]
private final int
private final ArrayDeque<FileTreeWalker.DirectoryNode>

Constructor Summary

AccessConstructor and Description
pack-priv
FileTreeWalker(Collection<FileVisitOption> options, int maxDepth)

Creates a FileTreeWalker.

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes/pops all directories on the stack.
private BasicFileAttributes
getAttributes(Path file, boolean canUseCached)

Returns the attributes of the given file, taking into account whether the walk is following sym links is not.

pack-priv boolean
isOpen()

Returns true if the walker is open.

pack-priv FileTreeWalker.Event
next()

Returns the next Event or null if there are no more events or the walker is closed.

pack-priv void
pop()

Pops the directory node that is the current top of the stack so that there are no more events for the directory (including no END_DIRECTORY) event.

pack-priv void
skipRemainingSiblings()

Skips the remaining entries in the directory at the top of the stack.

private FileTreeWalker.Event
visit(Path entry, boolean ignoreSecurityException, boolean canUseCached)

Visits the given file, returning the Event corresponding to that visit.

pack-priv FileTreeWalker.Event
walk(Path file)

Start walking from the given file.

private boolean
wouldLoop(Path dir, Object key)

Returns true if walking into the given directory would result in a file system loop/cycle.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

closedback to summary
private boolean closed
linkOptionsback to summary
private final LinkOption[] linkOptions
maxDepthback to summary
private final int maxDepth
stackback to summary
private final ArrayDeque<FileTreeWalker.DirectoryNode> stack

Constructor Detail

FileTreeWalkerback to summary
pack-priv FileTreeWalker(Collection<FileVisitOption> options, int maxDepth)

Creates a FileTreeWalker.

Exceptions
IllegalArgumentException:
if maxDepth is negative
ClassCastException:
if options contains an element that is not a FileVisitOption
NullPointerException:
if options is null or the options array contains a null element

Method Detail

closeback to summary
public void close()

Implements java.io.Closeable.close.

Closes/pops all directories on the stack.

Annotations
@Override
getAttributesback to summary
private BasicFileAttributes getAttributes(Path file, boolean canUseCached) throws IOException

Returns the attributes of the given file, taking into account whether the walk is following sym links is not. The canUseCached argument determines whether this method can use cached attributes.

Annotations
@SuppressWarnings:removal
isOpenback to summary
pack-priv boolean isOpen()

Returns true if the walker is open.

nextback to summary
pack-priv FileTreeWalker.Event next()

Returns the next Event or null if there are no more events or the walker is closed.

popback to summary
pack-priv void pop()

Pops the directory node that is the current top of the stack so that there are no more events for the directory (including no END_DIRECTORY) event. This method is a no-op if the stack is empty or the walker is closed.

skipRemainingSiblingsback to summary
pack-priv void skipRemainingSiblings()

Skips the remaining entries in the directory at the top of the stack. This method is a no-op if the stack is empty or the walker is closed.

visitback to summary
private FileTreeWalker.Event visit(Path entry, boolean ignoreSecurityException, boolean canUseCached)

Visits the given file, returning the Event corresponding to that visit. The ignoreSecurityException parameter determines whether any SecurityException should be ignored or not. If a SecurityException is thrown, and is ignored, then this method returns null to mean that there is no event corresponding to a visit to the file. The canUseCached parameter determines whether cached attributes for the file can be used or not.

walkback to summary
pack-priv FileTreeWalker.Event walk(Path file)

Start walking from the given file.

wouldLoopback to summary
private boolean wouldLoop(Path dir, Object key)

Returns true if walking into the given directory would result in a file system loop/cycle.

java.nio.file back to summary

private Class FileTreeWalker.DirectoryNode

extends Object
Class Inheritance

The element on the walking stack corresponding to a directory node.

Field Summary

Modifier and TypeField and Description
private final Path
private final Iterator<Path>
private final Object
private boolean
private final DirectoryStream<Path>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv Path
pack-priv Iterator<Path>
pack-priv Object
key()

pack-priv void
skip()

pack-priv boolean
pack-priv DirectoryStream<Path>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dirback to summary
private final Path dir
iteratorback to summary
private final Iterator<Path> iterator
keyback to summary
private final Object key
skippedback to summary
private boolean skipped
streamback to summary
private final DirectoryStream<Path> stream

Constructor Detail

DirectoryNodeback to summary
pack-priv DirectoryNode(Path dir, Object key, DirectoryStream<Path> stream)

Method Detail

directoryback to summary
pack-priv Path directory()
iteratorback to summary
pack-priv Iterator<Path> iterator()
keyback to summary
pack-priv Object key()
skipback to summary
pack-priv void skip()
skippedback to summary
pack-priv boolean skipped()
streamback to summary
pack-priv DirectoryStream<Path> stream()
java.nio.file back to summary

pack-priv Class FileTreeWalker.Event

extends Object
Class Inheritance

Events returned by the walk and next methods.

Field Summary

Modifier and TypeField and Description
private final BasicFileAttributes
private final Path
private final IOException
private final FileTreeWalker.EventType

Constructor Summary

AccessConstructor and Description
private
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv BasicFileAttributes
pack-priv Path
file()

pack-priv IOException
pack-priv FileTreeWalker.EventType
type()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attrsback to summary
private final BasicFileAttributes attrs
fileback to summary
private final Path file
ioeback to summary
private final IOException ioe
typeback to summary
private final FileTreeWalker.EventType type

Constructor Detail

Eventback to summary
private Event(FileTreeWalker.EventType type, Path file, BasicFileAttributes attrs, IOException ioe)
Eventback to summary
pack-priv Event(FileTreeWalker.EventType type, Path file, BasicFileAttributes attrs)
Eventback to summary
pack-priv Event(FileTreeWalker.EventType type, Path file, IOException ioe)

Method Detail

attributesback to summary
pack-priv BasicFileAttributes attributes()
fileback to summary
pack-priv Path file()
ioeExceptionback to summary
pack-priv IOException ioeException()
typeback to summary
pack-priv FileTreeWalker.EventType type()
java.nio.file back to summary

pack-priv final Enum FileTreeWalker.EventType

extends Enum<FileTreeWalker.EventType>
Class Inheritance

The event types.

Field Summary

Modifier and TypeField and Description
public static final FileTreeWalker.EventType
END_DIRECTORY

End of a directory

public static final FileTreeWalker.EventType
ENTRY

An entry in a directory

public static final FileTreeWalker.EventType
START_DIRECTORY

Start of a directory

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static FileTreeWalker.EventType
public static FileTreeWalker.EventType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

END_DIRECTORYback to summary
public static final FileTreeWalker.EventType END_DIRECTORY

End of a directory

ENTRYback to summary
public static final FileTreeWalker.EventType ENTRY

An entry in a directory

START_DIRECTORYback to summary
public static final FileTreeWalker.EventType START_DIRECTORY

Start of a directory

Constructor Detail

EventTypeback to summary
private EventType()

Method Detail

valueOfback to summary
public static FileTreeWalker.EventType valueOf(String name)
valuesback to summary
public static FileTreeWalker.EventType[] values()